Earlier quoted context omitted.
int n = 42; int acc = 0; Fixed Edit: Install http://wbond.net/sublime_packages/alignment and add this key binding `{ "keys": ["ctrl+shift+a"], "command": "alignment" }`.
That's actually right against the style guideline of many projects which tell you explicitly not to do this but to simply put the = sign and value right after the variable name and be done with it. Lining them up serves no purpose and does not in fact make the code easier to read.
How to name things in programming
81–90 of 177 posts
Re: How to name things in programming
#82I'm sure there is useful content in there, but holy crap is it ever obscured by most awful presentation.. Neither the slides nor the transcript are by any measure readable!
Re: How to name things in programming
#83Earlier quoted context omitted.
I agree, though there is a difference between being able to explain something and naming it. I've been known to forget the word "door", but I could quite happily explain how it worked.
Might be an outlier, IMO. And I guess this is exactly why author wants programmers to learn from the masters of spoken langauges-- ability to use the right word(s) to explain the concept/abstraction/property/behaviour/type. If one is unsure about how something works, then more often than not one would end up naming the thing wrong. By far and large, the most frustrating thing I've come across during code-reviews is g…
Re: How to name things in programming
#84An important rule is missing here: variables should be named with their scope in mind. So if a variable is longer lived and has larger scope its name should be that much more descriptive because when you're looking at it the only thing that will tie the value of the variable to the context within which it can be used is its name. So 'i' is fine for a loop control variable with a scope of five lines but totally inadeq…
Correspondingly, some objects don't need names at all. sorted(pairs, key=lambda p: p[1]) Though in that case you might prefer using the operator module. sorted(pairs, key=operator.itemgetter(1)) The aspect of Ruby that frustrates me the most is over-use of anonymous blocks when a good name would help me enormously.
Ruby gives you enough tools to write code clearly with good names if you want to. I think your complaint might be more about the particular style of Ruby a certain programmer wrote than the language itself.
Re: How to name things in programming
#85Earlier quoted context omitted.
I am suspicious of names containing "and". I agree about clarity over everything else, but then why even make a function if all it does is calling 2 functions in sequence, and you can't name it on higher level of abstraction? In this case wouldn't [x+1 for x in input_list.reversed()] be even clearer? True, functions allow you to change code in one place and affect many places (so they prevent "forgot to update one pl…
Function composition is by far the better solution, it is future proof and requires less memorization.
Re: How to name things in programming
#86Earlier quoted context omitted.
To be honest it actually makes code cleaner and therefore easier to read. It's like design have you heard about grid? this is the same thing. Your eyes have to flow the lines. If not everything seems a mess.
> To be honest it actually makes code cleaner and therefore easier to read. It does not logically follow from the code being "cleaner" that it is easier to read. Having to scan across a field of whitespace to get to the number makes it harder to read and easier to make mistakes. Having the indentation of the number be unrelated to the length of the variable name adds another aspect that makes it harder to read and ea…
parseModifier : String -> Outcome Modifier
parseModifier s = case s of
"shift" -> Ok Shift
"ctrl" -> Ok Ctrl
"alt" -> Ok Alt
"meta" -> Ok Meta
"command" -> Ok Meta
"windows" -> Ok Meta
x -> Err
I find it easier to read as is rather than if I dropped the alignment: parseModifier : String -> Outcome Modifier
parseModifier s = case s of
"shift" -> Ok Shift
"ctrl" -> Ok Ctrl
"alt" -> Ok Alt
"meta" -> Ok Meta
"command" -> Ok Meta
"windows" -> Ok Meta
x -> Err
As developers we spend more time reading code than editing it. Optimizing for readability seems like a better goal than optimizing for edit speed. Besides, most editors have functionality to align code. When I am looking over a file, the second example looks like a jumble of words to me, while the aligned version seems easier to parse (ha).Re: How to name things in programming
#87Earlier quoted context omitted.
Might be an outlier, IMO. And I guess this is exactly why author wants programmers to learn from the masters of spoken langauges-- ability to use the right word(s) to explain the concept/abstraction/property/behaviour/type. If one is unsure about how something works, then more often than not one would end up naming the thing wrong. By far and large, the most frustrating thing I've come across during code-reviews is g…
What does "Make life of" mean? As a native English speaker, I don't understand it; I presume it means "Make life better for", though the closest we have in English is probably "Make light of", which means something completely different (and is slightly funny in this context).
Re: How to name things in programming
#88One Clojure style guide actually recommends [0] certain single-letter names for input parameters: x and y for numbers, n for an integer, s for a string, f (and g and h) for functions. These are used in the clojure.core namespace, and their use elsewhere is thus (presumably) justified by a general common understanding of their meanings. [0] https://github.com/bbatsov/clojure-style-guide#naming
Functional programming languages use single-letter parameter names as a tool to help condense functions and allow easy parsing. This is largely due to their desire to emulate mathematical formulae. Interestingly, functional programming leads to a different naming custom that this presentation didn't really cover. To write "functionally" you want to have pure single-purpose functions and the name is supposed to descri…
Eg in the following snippet
map :: (a -> b) -> [a] -> [b]
map f (x:xs) = f x : map f xs
map _ [] = []
there's nothing known about x (apart from that you can apply f to it). So there's no way to give it a more descriptive name. We just don't have more information.Re: How to name things in programming
#89Earlier quoted context omitted.
Might be an outlier, IMO. And I guess this is exactly why author wants programmers to learn from the masters of spoken langauges-- ability to use the right word(s) to explain the concept/abstraction/property/behaviour/type. If one is unsure about how something works, then more often than not one would end up naming the thing wrong. By far and large, the most frustrating thing I've come across during code-reviews is g…
What does "Make life of" mean? As a native English speaker, I don't understand it; I presume it means "Make life better for", though the closest we have in English is probably "Make light of", which means something completely different (and is slightly funny in this context).
Re: How to name things in programming
#90Earlier quoted context omitted.
You will find, if you spend the effort to look, that different people process information completely differently. To someone who views this as a table, the above is so much more readable that it doesn't even bear thinking about. To someone who reads code the way a computer parses it (as I do), the added space can completely throw them for a loop. What the hell are you doing with n? Oh, if I look far enough, there is…
I'm curious, would you prefer your favorite music player list things like this Madonna, Rain, 3:45 Lady Gaga, Bad Romance, 4:17 U2, In God's Country, 3:57 LCD Soundsystem, I Can Change, 6:31 vs Madonna Rain 3:45 Lady Gaga Bad Romance 4:17 U2 In God's Country 3:57 LCD Soundsystem I Can Change 6:31 I'm not questioning that you find columnized code hard to read I'm just wondering would that apply to all forms of info? Y…
But most code that has structural isomorphism should be replaced by a loop or a function composition; repeated structural isomorphism is a redundancy that can be eliminated.
Aligning the initialization of a bunch of unrelated variables is a bit of a mixed case. Sequences of initialization are much more common in older languages, like C, that don't permit delaying the declaration. I don't have a strong opinion either way. If the data being initialized is structural, a tabular format should definitely be used, if it isn't fighting the tool (some IDEs etc. autoformat, or lint complains on unnecessary whitespace). If data is not structural and the variables aren't strongly related to one another, I don't see a good argument in favour of alignment, particularly when variable names can have wildly different lengths, e.g.:
source = 10;
timeout = 20;
wait_count = 30;
ch = 0;
accumulator = 40;
access_denied_retry_callback_list = [];
I find this substantially harder to read (see name to value and vice versa) than non-tabulated initialization. source = 10;
timeout = 20;
wait_count = 30;
ch = 0;
accumulator = 40;
access_denied_retry_callback_list = [];