Meh. As far as my knowledge goes, everything not zero is considered true in e.g. C or C++. Some companies, e.g. the one I work for, are using negatives for their error codes. So this piece of software may seem a bit odd, but IMO it's perfectly legit and reasonable.
Fairly confident I just had a mild stroke each time I read one of these options - because I know that somewhere in some codebase they all exist - AND probably went through code review.
Try showing them what that expression returns. Back when I was learning to program that's what made it click for me. I am going yo assume this is js so using the repl (or the console in your browser) could be a very visual way to explain it
Spaces increase the file size, and hence contribute to needing extra storage space and more data transmitted over the Internet, making climate change even worse. But no, it looks nicer, you planet hating monster!!
You're not the only one, mate. Our linter always wants me to insert brackets where they are just not bloody needed. I KNOW THE ORDER OF PRECEDENCE. The fact that my coworkers don't (apparantly), is their problem.
managers have 0 knowledge about programming. so if some noob coder shows up and says they can code and looks confident while saying it, managers are often bamboozled into believing it.
Not completely fair. I am a Director of Software Engineering and love to dive in with the team and bang out line after line of code. However, I agree that most managers have 0 knowledge there - and I am probably an anomaly!
Yeah, I mostly use Scala. It can catch exceptions for compatibility with Java, but it'll either turn them into a pattern match or the expression will evaluate to Try[T] (error monad).
Hmm, interesting. I'm not sure exactly how old he is but I think he's in his mid 40s. So not exactly old but just experienced... I suppose I'll be there soon!
Funny thing, I've been working for the past year or two maintaining a legacy VB app that uses the old "assign the return value to the function name as if it were a variable" pattern all over the place - the original developer retired. So would that be a zero return function? 😉
You can see that the code is highlighted. This means that IntelliJ knows a better way to write this piece of code. You can hover over the highlighted part and press “fix” to replace it with the IntelliJ suggested code.
I know it knows, but will it bulk fix everything? Never seen it do that. Part of the reason why I left the IntelliJ suite and prefer working with CLI tools now. I just can't integrate IntelliJ linting/formatting to CI. one way or another I have to switch to something else.
There is an option “code cleanup” that’s supposed to fix all these warnings. On small projects this seems to work fine, not sure how it performs on large projects.
A ternary operator with only literal boolean values is functionally identical to just using the condition (or inverting it and using it) except it's less readable and if you have optimization disabled it's probably slower.
The question"Is RETURN statement before END SUBROUTINE in Fortran codes considered a good practice?" doesn't have an accepted answer. The answer by janneb is the one with the highest score of 3:
As the Intel guide mentions, it's pointless since the "end subroutine" statement already handles it. Return is useful if you need to, say, return inside a loop or such (but then there's a school of thought saying you should structure your control flow such that you never return in the middle of a loop. YMMV).
This action was performed automagically.info_postDid I make a mistake?contactor reply: error
Given it's tagged as java, no. As soon as you would try to get the value of result, it would throw up a NullPointerException if I'm not completely mistaken.
I'm pretty sure it's invalid in C#, since bool? can't be implicitly converted to bool, if it is valid "value??other" is more clear about what it does, and I'm pretty sure you can't change the return type for comparison operator overloads
15
u/[deleted] Sep 01 '21 edited Sep 02 '21
return (result>=0?result>=0:result>=0) == (result==result); fixed it for you
(edit: bugfix)
69
u/Impossible_Average_1 Aug 31 '21
4
u/veedant Sep 01 '21
I feel very sorry for the maintainer of this codebase (you)
295
u/AL_O0 Aug 31 '21
Clearly the better option
2
u/fllr Sep 01 '21
Code like this tells me the person is inexperienced, and i take the time to help them out.
45
u/user_8804 Aug 31 '21
Return (result >= 0) is too simple
63
u/alexanderhameowlton Aug 31 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
63
u/JustAnotherGamer421 shameless Sep 01 '21
I hate everyone in this thread
Except image transcription boi
30
u/rofelixk Sep 01 '21
Some people I work with do that and even after I explain that it's not necessary, the don't get it, just keep doing it, it's infuriating
32
u/SomeOtherGuySits Aug 31 '21
Brackets like that annoy the fuck out of me
16
u/UselessAdultKid Sep 01 '21
How can these people can get a job and I can't lol
6
u/Igotbored112 Sep 01 '21
There's your C-style code. Alternatively:
Slight modifications required for variables other than ints.
I like this kind of bad code the best.
14
u/Shower_Handel Aug 31 '21
Whom among us hasn't been guilty of this at one point
4
u/ekolis Sep 01 '21
My boss likes this pattern:
Not sure what the purpose of the
retvalvariable is... why not just return null if the test fails?4
u/iamasuitama Sep 01 '21
That's my number 1 pet peeve when reading into a codebase. Instantly look up the git blame and remember not to trust their code.
2
u/[deleted] Sep 01 '21
There has to be a reason why. They couldn't have done this more than twice and not realized how redundant it is.
2
u/AlexAegis Sep 01 '21
idk about the java ecosystem but in js world I just run a round of prettier and eslint on the codebase and shit like this disappears.
2
u/[deleted] Sep 01 '21
I'm a beginner and don't understand why this is bad
2
u/R3D3-1 Sep 01 '21
A similarly useless and distracting pattern, that is now useless but a hold-over from pre-modern Fortran:
or
See https://stackoverflow.com/questions/58723975/is-return-statement-before-end-subroutine-in-fortran-codes-considered-a-good-pra
2
u/spock1959 Sep 01 '21
Guy I work with would do something like:
1
u/thequeergirl Sep 01 '21
def detect_lie(text, lie):return any(lie in line for line in text.splitlines())print(detect_lie(POST, FALSE_THING)) # False. No lies detected.1
u/daedalususedperl Sep 01 '21
Explicit is better than implicit, drinking is better than coding
1
u/rupr25 Sep 01 '21
Would this be valid if results was a nullable variable?
1
u/jonnyboyrebel Sep 01 '21
return !!resulthard to read, and succinct!
1
u/GorniYT Sep 01 '21
Yametekudastop
1
u/ITinyGiant Sep 12 '21
Imagine using a return statement.
1
u/RemizZ Sep 01 '21
Probably unpopular opinion: I like obvious bools written out for faster readability...
0
u/[deleted] Aug 31 '21
[deleted] — view deleted comment