Is all of coding/programming really that easy (or rather, logic based). Because I fully understood the OP despite having zero coding experience whatsoever.
This was really fun!
Logic-based, yes (I mean, obviously; that's how computers work). As easy as the OP, not really; the example is made to be the simplest possible one to illustrate the issue without distraction.
But yeah, coding and particularly its keywords like if, else, etc, are made to be as close as possible to (English) language as possible. Some languages are even closer; for example Pascal (if I remember correctly; I haven't used it since college, 25+ years ago) has "then" after the condition in the "if", and also BEGIN and END instead of open and close brackets.
If you had fun parsing through this, why don't you try learning to code? It
is really fun... well, to the sample population composed of me, at the very least. :D Let me know if you're interested and I can point you in the direction of some resources.
That's the same, but much less readable. So good luck getting it when you don't know what this way of writing means.
Uh... what? The ? : operator is not "less readable", or even particularly esoteric at all.
I would argue being able to impress employers with clever code is a real world application of clever solutions.
Nah. There's two types of people that you need to impress when applying for a the job:
- The higher ups that don't know shit about coding.
- The programmers that have probably endured enough of this "clever" (translation: fucking obnoxiously unreadable) coding to last a lifetime.
You can't impress the former with clever coding tricks, because they don't understand it. The latter will discard your application the instant they imagine themselves having to parse through code like that on a daily basis.
Bit of a sidetrack, but in C#, wouldn't case B fail because there's no default Return? Like, I'd have to do this if I wanted to add the explicit else case becuse without the second Return False, it wouldn't compile:
C#:
bool MyFunc()
{
if (situation)
{
return true;
}
else
{
return false;
}
return false;
}
Otherwise, I'd be forced to use A, right? I realise B is clearer to human readability.
Edit: Might this be a compiler quirk if it wouldn't otherwise do this for others?
The code you posted would actually show a warning (if not a compile error, depending on your settings) due to the dead code at the end. The last return at the end is not just redundant, it's unreachable.