Content deleted Content added
Jerryobject (talk | contribs) Nonlead-word nonproper noun MOS:CAPS MOS:HEADings-MOS:HEADCAPS > WP:LOWERCASE sentence case. WP:LINKs add. WP:BADEMPHASIS MOS:BOLDs > MOS:NOBOLD WP:ITALICs. Small WP:COPYEDITs WP:EoS WP:TERSE, MOS:NOTETHAT cut. |
|||
(13 intermediate revisions by 12 users not shown) | |||
Line 1:
{{Short description|Manner of writing source code}}
{{More citations needed|date=June 2016}}
'''Programming style''', also known as '''coding style''',
Maintaining a consistent style across a codebase can improve readability and ease of software maintenance. It allows developers to quickly understand code written by others and reduces the likelihood of errors during modifications. Adhering to standardized coding guidelines ensures that teams follow a uniform approach, making the codebase easier to manage and scale. Many organizations and [[Open source|open-source]] projects adopt specific coding standards to facilitate collaboration and reduce cognitive load.
Line 15 ⟶ 14:
Common elements of coding style include:
* ''Indentation and [[whitespace character]] use'' – Ensures consistent block structures and improves readability.
* ''Naming conventions'' – Standardizes how [[Variable (computer science)|variables]], [[Function (computer programming)|functions]], and [[Class (computer programming)|classes]] are named, typically adhering to [[Camel case|camelCase]], [[
* ''Capitalization'' – Dictates whether keywords and identifiers are capitalized or lowercase, in line with language syntax.
* ''Comment use'' – Provides context and explanations within code without affecting its execution.
=== Indentation ===
Indentation style can assist a reader in various
▲Indentation style can assist a reader in various way including: identifying control flow and blocks of code. In some programming languages, indentation is used to [[off-side rule|delimit blocks of code]] and therefore is not matter of style. In languages that ignore whitespace, indentation can affect readability.
▲For example, formatted in a commonly-used style:
<syntaxhighlight lang="c">
Line 48 ⟶ 46:
==== Notable indenting styles ====
===== ModuLiq =====
{{Further|ModuLiq}}
The '''ModuLiq''' Zero Indentation Style groups by empty line rather than indenting.
Example:
Line 64 ⟶ 61:
===== Lua =====
{{Further|Lua}}
<syntaxhighlight lang="lua">
if hours < 24 and minutes < 60 and seconds < 60 then
Line 77 ⟶ 74:
===== Python =====
{{Further|Python (programming language)}}
<syntaxhighlight lang="python">
Line 92 ⟶ 89:
===== Haskell =====
{{Further|Haskell}}
Haskell is a declarative language, there are statements, but declarations within a Haskell script.
▲[[Haskell]], like Python, has the ''off-side rule''. It has a two-dimension syntax where indenting is meaningful to define blocks (although, an alternate syntax uses curly braces and semicolons).
▲Haskell is a declarative language, there are statements, but declarations within a Haskell script.
Example:
Line 135 ⟶ 132:
=== Vertical alignment ===
Some programmers consider it valuable to align similar elements vertically (as tabular, in columns), citing that it can make typo-generated bugs more obvious.
Line 194 ⟶ 190:
=== Whitespace ===
A [[free-format language]] ignores [[whitespace character]]s: spaces, tabs and new lines so the programmer is free to style the code in different ways without affecting the meaning of the code. Generally, the programmer uses style that is considered to enhance [[readability]].
▲A [[free-format language]] ignores [[whitespace character]]s: spaces, tabs and new lines so the programmer is free to style the code in different ways without affecting the meaning of the code. Generally, the programmer uses style that is considered to enhance [[readability]].
The two code snippets below are the same logically, but differ in whitespace.
Line 249 ⟶ 244:
== References ==
{{Reflist}}
[[Category:Source code]]
|