Over the years I've relaxed my brace and paren attitudes. If someone has been consistent, after a few minutes I can get the feel of their style and focus on the logic of their code and get hacking.
What still ties me up in knots, and this is about my own coding habits, not other people's code, is long lists of function parameters. I can never decide which is more appealing to the eyes, easier to read, and all while conserving vertical space. So...
public function someBigLongFunctionNameThatTakesLotsaSpace( $paramOne, $paramTwo, $paramThree, $paramFour) {
...
...
}
or
public function someBigLongFunctionNameThatTakesLotsaSpace( $paramOne,
$paramTwo,
$paramThree,
$paramFour) {
...
...
}
or
public function someBigLongFunctionNameThatTakesLotsaSpace( $paramOne, $paramTwo,
$paramThree, $paramFour) {
...
...
}
or
public function someBigLongFunctionNameThatTakesLotsaSpace(
$paramOne,
$paramTwo,
$paramThree,
$paramFour) {
...
...
}
Another readability hint, don't pass operations as arguments (the glovesAreAvailable). I've stopped doing this a long time ago and it really helps maintenability.
It's nitpicking, I know. But it really helps writing clearer code
Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
Sure, the core dev team, who made the language, also made tools for static analysis,linter, code formatting and incorporated some of the rules in the compiler too, this you get these advantages: blog.golang.org/go-fmt-your-code
easier to write: never worry about minor formatting concerns while hacking away,
easier to read: when all code looks the same you need not mentally convert others' formatting style into something you can understand.
easier to maintain: mechanical changes to the source don't cause unrelated changes to the file's formatting; diffs show only the real changes.
uncontroversial: never have a debate about spacing or brace position ever again!
Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
That's the beauty, it doesn't matter and we do not care. We solve problems, we are engineers, coding is just a 20% of our jobs and we shouldn't focus on things that the IDE should do for us.
Unless someone makes a PR to the official Go tool and convince the community that is better his way.
I tried closing braces at the end of the line, 1st alternative syntax, made the code look more "pythonic". Soon gave it up though because of the inconvenience of always having to fix code when removing or adding lines, and removing lines with braces wasn't just a mark line then push backspace anymore if you still needed the braces.
Awesome title :D
Over the years I've relaxed my brace and paren attitudes. If someone has been consistent, after a few minutes I can get the feel of their style and focus on the logic of their code and get hacking.
What still ties me up in knots, and this is about my own coding habits, not other people's code, is long lists of function parameters. I can never decide which is more appealing to the eyes, easier to read, and all while conserving vertical space. So...
or
or
or
Probably the last one is better. For me, I try to prevent my eyes travelling far to the right. That makes me lose focus easily.
Agreed. Also, I don't mind having multiple parameters in one line, but I really need them to be on the left side.
Thanks :D
Another readability hint, don't pass operations as arguments (the glovesAreAvailable). I've stopped doing this a long time ago and it really helps maintenability.
It's nitpicking, I know. But it really helps writing clearer code
I agree for languages where named arguments are not available.
In Go we don't have problems like these, we're Zen ๐.
I'll not that familiar with go - could you please explain how go solved that syntax problem? :)
Sure, the core dev team, who made the language, also made tools for static analysis,linter, code formatting and incorporated some of the rules in the compiler too, this you get these advantages:
blog.golang.org/go-fmt-your-code
A Go "proverb" is "Gofmt's style is no one's favorite, yet gofmt is everyone's favorite", meaining each dev will not like something about the Go standard way, but overall you like it's benefits, because everyone obeys it.
Cool. But how does it indent function calls with many parameters? :D
The rust language has a similar thing, but unfortunately, it will indent many arguments far to the right.
That's the beauty, it doesn't matter and we do not care. We solve problems, we are engineers, coding is just a 20% of our jobs and we shouldn't focus on things that the IDE should do for us.
Unless someone makes a PR to the official Go tool and convince the community that is better his way.
I tried closing braces at the end of the line, 1st alternative syntax, made the code look more "pythonic". Soon gave it up though because of the inconvenience of always having to fix code when removing or adding lines, and removing lines with braces wasn't just a mark line then push backspace anymore if you still needed the braces.
Thankfully, I've rarely seen the parenthesis indentation you consider common, so hopefully I won't have to share this article too often ;)
That's great :)