2 ms·
> So time spent aligning parameters to make code more readable is well spent, if you ask me. How is this[1] more readable than this[2]? [1] https://github.com
by scrollaway 9y ago
> So time spent aligning parameters to make code more readable is well spent, if you ask me.
How is this[1] more readable than this[2]?
[1] https://github.com/HearthSim/python-hslog/blob/5a6ad9a29a7d46672d563915ecfae74f3bfda94f/hslog/packets.py#L44-L53 https://github.com/HearthSim/python-hslog/blob/5a6ad9a29a7d4...
[2] https://gist.github.com/jleclanche/ef40058731061e26d218e2a4c99099b0 https://gist.github.com/jleclanche/ef40058731061e26d218e2a4c...
Let the lines get long enough and the latter is actually quite a bit harder to read; try to follow the variable all the way to its value and you might actually jump and be one line off.
I deeply care about readability and code style, that's why I'm replying here :) And in all the codebases I have read and written, alignment has consistently been harmful to readability and maintenance.
- swift 9y agoWhen I hear "aligning parameters", I think more of the difference between this: someFunction(firstParam, secondParam, thirdParam, fourthParam); And this: someFunction(firstParam, secondParam, thirdParam, fourthParam); I've always found the second much easier to read, especially when there are multiple levels of nested expressions, and it's a style that has been encouraged on every project I've worked on. I agree that aligning '=' is actively harmful in the example you give, and that it's harmful in most situations where it's used. I've encountered very rare instances where it's helpful, though. Sometimes you have a sequence of values defined by expressions that follow a pattern: enum someEnum { FIRST = BASE + MASK & (1 << 0), SECOND_VALUE = BASE + MASK & (1 << 1), TH = BASE + MASK & (1 << 2) } Aligning the expressions can make it more clear what the pattern is and how it differs from value to value: enum someEnum { FIRST = BASE + MASK & (1 << 0), SECOND_VALUE = BASE + MASK & (1 << 1), TH = BASE + MASK & (1 << 2) } Often there are other ways to handle the issue, such as hiding the expression behind a macro or a function call; when that's more readable, that's the way to go. But in cases where writing the expression explicitly ends up being more readable, I find alignment to generally be a win in this case.