Writing code: Difference between revisions

From XPUB & Lens-Based wiki
Line 32: Line 32:


* Imperative
* Imperative
Commands, traditional "programming" languages like [[JavaScript]], [[Python]]
* Declarative
* Declarative
Descriptive, "Markup" languages like [[HTML]], [[CSS]]


== Special Characters ==
== Special Characters ==

Revision as of 09:54, 23 September 2014

<slidy theme="aa" />

Writing Code

Writing code has special demands from other kinds of writing.

Specialised tools exist for writing code that help make some of the complexities of code writing manageable.

Code Editor

A code editor has features like:

  • Ability to work with many files & languages at the same time
  • Syntax coloring for different languages
  • Symbol matching
  • Commenting Shortcut
  • Tab/Space "sensitivity"
  • "Show invisibles" feature

Examples:

  • Sublime Text Unfortunately not free software, it is however free to use (it nags about registering from time to time), and it's cross platform
  • gedit

White space

Characters like space, tab, carriage return and new line or basically anything that doesn't print a visible symbol.

While many languages are said to "ignore" whitespace (like HTML) ... (one space is the same as 20 spaces), others are very sensitive to subtle differences (like Python considering tabs vs. spaces).

Code Types

  • Imperative

Commands, traditional "programming" languages like JavaScript, Python

  • Declarative

Descriptive, "Markup" languages like HTML, CSS

Special Characters

Matching symbols

< > Angle Brackets
[ ] Square Brackets
{ } Curly Brackets
( ) Parentheses
' ' Single Quotes
" " Double Quotes

What the $#!@

- dash
. dot
_ underscore
= equals sign
$ dollar sign
/ slash (forward)
\ backslash
# hash
! exclamation mark (aka bang)
@ at sign
* star (asterisk)

Syntax

Each language has rules determining proper structure. Files that have structural errors are said to have syntax errors (in the case of imperative languages) or else described as not being well-formed, invalid, or just plain broken.

Some programs when interpreting code are more permissive than others. Web browsers will generally speaking display something, even when HTML code is syntactically incorrect. When displaying an SVG graphic however, any errors typically means that nothing but a short complaint will be shown that the file is invalid.

Markup

Many coding languages use a notion of markup tags inspired by the SGML family of languages