News for hackers. Stuff that matters.
Re:Most common mistakes during interviews by gnusty_gnurc on Sunday August 30, 2020 @01:43PM (#24324444)
> Has complexity or efficiency ever come up in a team discussion? Nope. Do we have use for high efficiency solutions at scale? Not particularly.

Not only that - I often see atrocious code. Stuff like comparing boolean expressions against true/false. Stuff that makes me question basic competence of the person writing it.

Re:Most common mistakes during interviews by cguess on Sunday August 30, 2020 @01:50PM (#24324510)
> Stuff like comparing boolean expressions against true/false

I do this sometimes if it makes the code clearer. Sometimes it's not 100% clear if you're just coming in that a function returns a boolean. Sometimes you just want to remind yourself and it sneaks past a code review. I've been coding for 20 years across a dozen plus languages, and some just handle truthiness differently and it's easier to just make sure (looking at you, Javascript). Sometimes null is false, sometimes it's not, sometimes an empty string is false, sometimes it's not.

Any compiler, JIT, optimizer etc. will completely ignore the comparison anyways so there's 0 runtime issue with it.

Re:Most common mistakes during interviews by RandoHolmes on Sunday August 30, 2020 @02:19PM (#24324732)
> do this sometimes if it makes the code clearer.

As do I, the above poster is just super judgemental and probably not a lot of fun to work with.

An observation I've had over the years is that often times developers will come to conclusions that they ought not to. The idea that typing out "== false" indicates you don't understand bools is a non-sequitur.

Re:Most common mistakes during interviews by xorcist on Monday August 31, 2020 @03:41PM (#24335202)
When could an extra "== true" or "== false" possibly make anything clearer?

  if not (x > 5)
looks normal,

  if (x > 5) == false { .. ]
is just confusing.

Why would it matter if a function returned a boolean? It's either compared for truthiness, or the comparison for truthiness or compared for truthiness, even in the most dynamic languages.

Re:Most common mistakes during interviews by alpha_squared on Sunday August 30, 2020 @02:03PM (#24324604)
> Sometimes it's not 100% clear if you're just coming in that a function returns a boolean

I'd argue the function isn't named appropriately, then.

> Sometimes you just want to remind yourself and it sneaks past a code review

Remind yourself what, exactly?

> dozen plus languages, and some just handle truthiness differently and it's easier to just make sure (looking at you, Javascript)

I'd argue that it's on the developer to know and work with the language's semantics (and I say this as someone who's not a fan of JS). Trying to write code that is nearly language agnostic in semantics will leave out a whole lot of language-specific value.

Re:Most common mistakes during interviews by RandoHolmes on Sunday August 30, 2020 @02:16PM (#24324712)
> I'd argue the function isn't named appropriately, then.

Maybe yes, maybe no. The point is that adding "== true" makes it more clear and should therefore be done.

Re:Most common mistakes during interviews by coin on Sunday August 30, 2020 @03:25PM (#24325214)
For strongly type languages (like Java), how can ==true make it more clear?
Re:Most common mistakes during interviews by MattGaiser on Sunday August 30, 2020 @02:04PM (#24324619)
Why is that so horrible? I prefer it because I am prone to missing the ! when tired (which is a problem as my project has complex conditionals).

Functions are not always consistent about returning a Boolean either. Bad design/naming, but you work with what you have got.

Re:Most common mistakes during interviews by hinkley on Sunday August 30, 2020 @03:11PM (#24325117)
Well, for one case, I’ve seen people work really hard to test a == b, or alternatively a != b when a and b are Booleans.

I think some classes were not mandatory in school, or people hated that class.

Re:Most common mistakes during interviews by RandoHolmes on Sunday August 30, 2020 @02:14PM (#24324692)
this attitude is elitism and needs to stop.

I will sometimes compare against true/false, it doesn't mean I don't understand boolean logic, it means I feel like it's more clear.

It could also be that I'm in a language with truthy values and I specifically only want to compare to real boolean values.

You really need to stop and ask yourself why you're so judgemental about code. Because that's a you problem, not a them problem.

If I ever had a co-worker try and tell me I don't understand boolean logic because I felt like typing it out was more clear I'd laugh in their face.

Re:Most common mistakes during interviews by gnusty_gnurc on Sunday August 30, 2020 @02:31PM (#24324820)
No it’s not saying someone doesn’t understand Boolean logic.

It’s visual noise. This isn’t an issue with truthiness either. I’m talking normal java code. Where if I see an if-statement, clearly the thing inside doesn’t need comparison against true or false unless you want to add another comparison just for fun and mental gymnastics.

Re:Most common mistakes during interviews by fingerlocks on Sunday August 30, 2020 @03:00PM (#24325034)
It’s the opposite of noise by making the logic more precise. Suppose you have unwrapped optionals or result types, or need to specifically handle a null type differently from a false. It’s also helpful when refactoring changes a function signature.

Are you young or early in your career? I think the extra verbosity is something you come to appreciate the “the hard way” over the years.

Re:Most common mistakes during interviews by gnusty_gnurc on Sunday August 30, 2020 @03:14PM (#24325134)
> It’s the opposite of noise by making the logic more precise

There's cases where this might make sense (when things like truthiness are unclear). But in any of the cases I've seen, it's where things are pretty obvious and even when things are explicitly boolean types.

Write the boolean expression and if it doesn't fit or has lots of parts, define them separately above the conditional with clear names.

People seem upset by this, but idk it seems like common sense.

I'm not sure I understand how `if (someCondition == true) {...}` is preferable to `if (someCondition) {...}`

Re:Most common mistakes during interviews by RandoHolmes on Sunday August 30, 2020 @03:46PM (#24325394)
> People seem upset by this

No one is upset, they simply disagree with you...

Maybe avoid trying to dismiss people and look at what they're actually saying? There are things you put in code that others are unfairly judging you for.

something something glass houses.

Re:Most common mistakes during interviews by ubercow13 on Sunday August 30, 2020 @03:25PM (#24325216)
It's such an irrelevant surface-level thing to judge someone's intelligence and coding ability on. Just because they wrote that doesn't mean they don't understand that it could be simplified or that they aren't capable of handling much more complex boolean logic. Sometimes I write things like that just because I am typing my thoughts into code as they come to me, and that's just how I happened to vocalise it in my head.
Re:Most common mistakes during interviews by gnusty_gnurc on Sunday August 30, 2020 @03:41PM (#24325348)
This is usually in context of massive classes and functions that are regularly 100+ lines. It’s not organized or thoughtful and an absolute pain to work with.

Idk this is just my experience with disorganized code and unclear.

Re:Most common mistakes during interviews by thdc on Sunday August 30, 2020 @02:44PM (#24324922)
If a case like this pops up, how about asking them why they did it like that and then making your judgement based on response instead of questioning their competence right away?

Response 1: I thought it would be clearer with the explicit comparison. (fine, then you can bring in your own opinion and maybe have a nice discussion)

Response 2: You don't need == true? I never knew. (bad)

Another common scenario that is complained about: using `this` with instance variables when it's technically unnecessary.

Re:Most common mistakes during interviews by coin on Sunday August 30, 2020 @03:35PM (#24325290)
The point is that "if" branches based on a boolean value. A comparison is just one way to produce a boolean value. There's nothing explicit by adding "==true". It just show a lack of understanding of "if".
Re:Most common mistakes during interviews by xorcist on Monday August 31, 2020 @03:47PM (#24335250)
If an extra "== true" can be considered more precise, would

  if ((conditional == true) == true)
be even more precise?
Re:Most common mistakes during interviews by gnusty_gnurc on Sunday August 30, 2020 @03:44PM (#24325369)
Precisely. Thank you.