User:ArielGlenn/Sandbox

Figuring out some standard formatting for code examples for dumps (and other) knowledge sharing sessions.

Here's a first sample...

This is an example of how not to exit from a python script.

You can see that the author has carefully kept to python style guidelines as far as use of indentation and blank lines, even going so far as to avoid extraneous code in __main__ to avoid pylint errors.

Nonetheless, blah blah blah.



This trick avoids pylint whines about how the constant you were going to define in __main__ doesn't have an approved uppercase name etc. Plus it's polite behavior to have all of your functionality in methods and invoke the ones you want out of __main__ if the script is executed as standalone.



Turn this into two templates:
 * one for everything through the syntaxhighlight tag, with params: number of brs to write if any, link target if you have one, language, highlight if any, start if needed, if syntax is omitted we just use plain text; also allow background color (only good for plain text boxes)
 * second one to close all the tags

If content wraps in the commentary box and it's not capped to a max width, the box pushes a little into the left column. Added a max width which I prefer anyways.

This can now be done by template; see Template:CodeCommentary.

Resources used when writing that simple little template, because I've forgotten everything I knew:
 * Manual:Coding_conventions/Python to discover how code syntax is highlighted around here
 * Extension:SyntaxHighlight to get the details of params to the extension tag
 * w:Template:Flex_columns/styles.css to see how flex is commonly used
 * commons:Category:Linearicons.com_icons for the hand pointer and eyes icons
 * Template:Sandbox for soooo many experiments
 * for looking at existing templates and stealing liberally
 * Template:Sandbox/doc to get a clue about template documentation these days
 * Template:Div col and Template:Div col/doc to get even more of a clue
 * Help:Extension:ParserFunctions for #ifeq and every other dang thing I forgot
 * Template:Codesample to rediscover #tag which I had forgotten about completely as well
 * Help:Magic words for #tag requiring the content param even if empty
 * Help:Images to figure out why "right" and "top" don't play well together
 * Help:Parser functions in templates for more #ifeq "fun"
 * Module:String to insert my desired number of line breaks
 * Help:TemplateData which I should have read before adding template data and never did
 * wikt:Category:English_vulgarities which I really should have used, as I got pretty repetitive at points

Now, off to write some knowledge-sharing docs!