Remarks on Style

# How long is a line?

Ideally, a physical line of code contains exactly one q statement, and a q statement encodes exactly one thought.

Some thoughts are too large or complex to represent in a single readble q statement. Some thoughts are too small or trivial to justify the expenditure of a whole physical line.

An example of a line which contains several q statements, each of which encodes a small piece of a single thought:

a:x 0; b:x 1; c:x 2; d:x 3; e:x 4


Note

Observe how the blanks are used after each semicolon to achieve visual separation. This is legitimate, since whitespace should help us see computational structure. Not so in

v:m[a; b; ]
where the spaces create a visual obstacle.

Sometimes a thought consists of a simple operation on parts whose construction is complicated:

r:(…x 0…;…x 1…;…x 2…;…x 3…)


Where the ellipses stand for complicated calculations on the parts of x. if the calculations are mutually independent, break the construction of r into a set of preliminary steps:

d:…x 3…;
c:…x 2…;
b:…x 1…;
a:…x 0…;
r:(a;b;c;d)


A good rule of thumb is that a line should consist of no more than 50 characters, including the initial spaces. This leaves room for 40 or 50 characters’ worth of comment.

If your function looks tall and skinny, see whether you’re breaking ideas up into pieces which are too small. If your function looks short and fat, see whether you‘re trying to express more than one idea on each line.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5527989268302917, "perplexity": 1900.875111552589}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-39/segments/1568514572934.73/warc/CC-MAIN-20190916200355-20190916222355-00051.warc.gz"}