Indentation Programming style
1 indentation
1.1 moduliq
1.2 lua
1.3 python
1.4 haskell
indentation
indent styles assist in identifying control flow , blocks of code. in programming languages indentation used delimit logical blocks of code; correct indentation in these cases more matter of style. in other languages indentation , white space not affect function, although logical , consistent indentation makes code more readable. compare:
or
with like
the first 2 examples easier read because indented in established way (a hanging paragraph style). indentation style useful when dealing multiple nested constructs.
note example same simply:
moduliq
the moduliq 0 indent style groups carriage returns rather indents. compare of above to:
lua
lua not use traditional curly braces or parenthesis. if/else statements require expression followed then, , closing if/else statement end.
indentation optional. and,or,not used in between true/false statements.
they true/false statements, as
would mean false.
python
python uses indentation indicate control structures, correct indentation required. doing this, need bracketing curly braces (i.e. { , }) eliminated. on other hand, copying , pasting python code can lead problems, because indentation level of pasted code may not same indentation level of current line. such reformatting can tedious hand, text editors , ides have features automatically. there problems when python code being rendered unusable when posted on forum or web page removes white space, though problem can avoided possible enclose code in white space-preserving tags such <pre> ... </pre> (for html), [code] ... [/code] (for bbcode), etc.
notice python not use curly braces, regular colon (e.g. else:).
many python programmers tend follow commonly agreed style guide known pep8. there tools designed automate pep8 compliance.
haskell
haskell has off-side rule, i.e. has 2 dimension syntax indentation meaningful define blocks. although alternate syntax uses curly braces , semicolons. haskell declarative language, there statements, declarations within haskell script. example:
may written in 1 line as:
haskell encourage use of literate programming, extended text explain genesis of code. in literate haskell scripts (named lhs extension), comment except blocks marked code. program can written in latex, in such case code environment marks code. each active code paragraph can marked preceding , ending empty line, , starting each line of code greater sign , space. here example using latex markup:
and example using plain text:
Comments
Post a Comment