Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
OllieVee3988yI do understand your point, although I gave Up discussing this with colleagues.
But still both are way better than
If(condition)
//creepy oneliner -
I personally prefer having spaces around the condition in parentheses:
if (condition) {
...
}
And I love oneliners without curved brackets for cases like this:
if (first check)
throw new Exception(...);
if (second check)
throw new Exception (...);
... -
31415098y@runfrodorun In this situation, the ambiguity is caused by an ambiguous variable name. If for example the value of "state" refers to something being active or inactive, "active" or "isActive" would be a much better choice.
But I agree, there might be situations where this could be appropriate.
I was originally referring to people who use this style for every single expression, simply because they don't actually understand what a boolean expression is. -
I'm the opposite here. I used to write the second style in PHP, and still do
However, in my C# projects the first style just sticks -
SSDD47978yI bet you're the kinda developer that would comment on a PR that it should be done the other way.
So long as it works. To each their own. -
JTBringe6098y@itsdaniel0 Yeah, whenever you try to change it Visual Studio tells you to fuck off and reverts back.
-
JTBringe6098y@Salkir Kill him and become the new team leader. Then you'll be the one to make all the rules.
If it works for the Sith, it should work for you. -
31415098y@runfrodorun I agree with everything you said. From a C perspective, your issues with my statements certainly seem reasonable.
At the moment, I mostly have to work with (and think in) Java, because of university and work. -
Wack63118y@runfrodorun the java compiler can do a lot of amazing optimisations, as long as the data you provide has a "pattern" and there ain't to much multithreading going on.
My favorite example of a java compiler going nuts is still
```
boolean check = true;
while (check) {
...
}
```
Will compile to something like
```
while (true) {
...
}
```
If it doesn't find a `check = false;` assignment within the loop. -
I like spaces.
if (condition) {
}
You can lint your team's code so it is consistent all throughout. -
abcdev30988yThat's why so many way to write, right? Let them code in the way they like. Developing is creating something, i believe. It's okay to have some view exact opposite of yourself. Hate is such a strong word.
-
Ok but why are the people who write the first way perfectly ok with wasting a line every condition and function? Do you want to see less of your code at a time?
-
First one is PSR-2 Standard. Better follow that standard when you are work as team. :-)
-
Kodoyosa98y@theorion you mean better follow that standard if your team work with that one. And I don't think first one is psr-2.
Most of the time (most common) :
function bar()
{
//code
}
And (if case)
if (/*condition*/) {
//code
}
(Check php-fig.org or just use plugins on your favorite ide/text editor to help you) -
spacem18448yI think most people would prefer perfectly clean code to something shitty but for the style just use the standard.
Look online at any official c# documentation and you will see the first being used. Look at javascript documentation you will see the 2nd.
if
(
notFollowingStandardConvention
){ console.log
(
'why?'
)} -
juchiast628y
-
31415098y@juchiast I see that one way too often, sometimes even as:
if (condition == true) {
return true;
} else {
return false;
}
IntelliJ IDEA is actually able to convert that into
return condition;
with a single keyboard shortcut. That's the only thing keeping me sane when I have to work with certain people's code. -
I actually learned the second one first and thought the same but then when a professor said a reason why he does it, it simple made more sense. It's easier to see if one is missing and I couldn't find a reasoning similar for the second you mentioned so from then on I started doing like the first one
-
curlyDev4728yBecause with big if statements i need to look to the whole condition before i see the { .
Sometimes you just want to see where the condition ends, and the first one is the best for this. -
While I prefer that way too with minor variation(extra space), the syntax is perfectly valid to the compiler and whatever works works. If any little thing bothers you that says something about you more than it does about the thing. Let all write how they want and let yourself just format their code if you need to review it as most tools can do this for you.
Not doing that is like complaining about how your feet hurt because of all the sharp things on the ground. Why don't they remove all the sharp things off the ground? Instead, why don't you just put on some decent shoes? Do your own damn formatting however you like it.
Related Rants
I really hate people who prefer this coding style:
if (condition)
{
// something shitty here
}
Instead of this:
if(condition){
// perfectly clean code
}
undefined
php
coding style