I am looking for a quick and efficient way to split code and make it printable. I work in coder magazine, and it is always very difficult to prepare the code for printing, because the space in one column is limited. Now I do it manually, and it is very tiring. Let me give you an example. This is the code I'm working on right now (already formatted / dictated in my own style), it is for Android:
private void GetFiles() { listBox1.Items.Clear(); var storeFile = IsolatedStorageFile. GetUserStoreForApplication(); string fileString = System.IO.Path.GetFileName("*"); string[] files = storeFile.GetFileNames("*"); for (int i = 0; i < storeFile.GetFileNames("/" + fileString).Length; i++) { String fileName = storeFile.GetFileNames(fileString)[i]; String ext = fileName.Substring(fileName.Length - 3); if (ext == "png") listBox1.Items.Add(fileName);
}}
note that
var storeFile = IsolatedStorageFile. GetUserStoreForApplication();
- one line. This is too long for a column for the press, so I separate the closest logical gap (here is the period) and the indents of the second part of the line with 4 spaces (inline always indents by 2 spaces). I know this is not the best way, it is difficult to understand. That's why I'm looking for an authoritative answer from a wide range of software developers. I have to work not only with C ++ code, but also with Assembler, JavaScript, Ruby and Python. The latter is a separate issue - it depends on the indentation, so I have to be especially careful with the indentation.
So the question is: which is the best way to format code in a limited log space? How do you prefer? Please suggest your own ideas. Each answer is highly appreciated.
UPD : this is what it looks like in the magazine now:
. This can help you solve this problem. Too long lines are broken into '\', and the last part of the line is indented. Not too obvious, is it? = (
source share