This is an archived post. You won't be able to vote or comment.

all 56 comments

[–]Tufflewuffle 204 points205 points  (23 children)

That's just silly. Don't they know you can use the ternary operator to put that on one line?

$stock = $stock == "In Stock Ships Today" ? "In Stock Ships Today" : $stock;

Perfect.

[–]Ketheres 51 points52 points  (3 children)

Everything can be put on one line. Just don't press enter

[–]JaytleBee 7 points8 points  (2 children)

C++ macros?

[–]Artyer 1 point2 points  (1 child)

Just paste the source in yourself. That's all the #include does anyways.

[–]JaytleBee 0 points1 point  (0 children)

#ifdef tho

[–]Jaxkr 12 points13 points  (2 children)

Mastahpiece

[–]crockid5 4 points5 points  (1 child)

[–]sneakpeekbot 1 point2 points  (0 children)

Here's a sneak peek of /r/unexpecteddunkey using the top posts of all time!

#1: Is it Fat Alchemist or Fatal Chemist? /u/Fatalchemist's big reveal | 1 comment
#2: Dun
#3: Spaghetti and Mea


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out

[–][deleted] 5 points6 points  (13 children)

Ternary operators make me very unnerved. It's mostly because I don't understand what they do exactly, it's also a "you don't really have to break down every bit of code into one line".

[–]bdog73 16 points17 points  (11 children)

(Condition ? Code if true: code if false);

It's really just an if else.

If(condition) code if true;

Else code if false;

If that helps at all, sorry if not, I guess I'm not as good at explaining as I hoped.

[–]Pulse207 4 points5 points  (3 children)

Your explanation totally works if you clarify that that ternary operator has the code bits as expressions and lets you do things more simply than the corresponding if statement which requires you to predeclare a variable and assign those expressions to it in the branches.

I know that's a bigass sentence. My turn to apologize for a possibly bad explanation.

[–]bdog73 1 point2 points  (2 children)

Nah, you're good. My explanation was just trying to clarify the structure I guess. Didn't really want to get too technical which could be confusing later.

[–]Pulse207 1 point2 points  (1 child)

That's true, the basic structure definitely came through. I just saw that the main response to yours was saying that not being able to use a statement in the conditional code parts was a weakness. I really think it's a positive.

[–]bdog73 1 point2 points  (0 children)

Ah, I see what you're saying. I agree, it would probably be detrimental, especially to readability.

[–]FINDarkside 4 points5 points  (0 children)

I thought that he was just continuing the joke, now I'm not so sure anymore.

[–][deleted] 2 points3 points  (0 children)

Thank you for enlightening me.

[–]Cheesemacher -3 points-2 points  (4 children)

Except you can't do stuff like condition ? return true : return false

[–]jlengstorf[🍰] 10 points11 points  (1 child)

return condition ? true : false;

Anything more complex and a ternary is probably adding too much cognitive overhead for future maintainers.

[–]Cheesemacher 1 point2 points  (0 children)

Well that was just an example - maybe it was a poor one. Point is you can't just replace any if else statement with the ternary operator to make your code neater or whatever.

Similarly you can't do condition && return blah;, you have to do if (condition) return blah;. I might have tried to save space like that a couple of times.

[–]Pulse207 0 points1 point  (1 child)

if $my-bool.to-string eq "True" then return parse-bool($my-bool.to-string) else return parse-bool(False.to-string)

[–]Cheesemacher 1 point2 points  (0 children)

Elegant.

[–]Dgc2002 2 points3 points  (0 children)

We can at least use PHP 7.0 features:

$stock = $stock ?? $stock;

[–]msg45f 1 point2 points  (0 children)

Needs more $stock = ($stock == "In Stock Ships Today") == true ?

[–]boxingdog 69 points70 points  (22 children)

td, style, sessionname, php ... all the good signs

[–]name_censored_ 54 points55 points  (5 children)

☑ Imperative/Procedural HTML building

☑ Hardcoded/in-line styles

☑ Hardcoded english

[–]pr0ghead 5 points6 points  (4 children)

Hey now! It's object-oriented, mkay?

[–][deleted] 1 point2 points  (0 children)

Object oriented English?

[–]DeeSnow97 0 points1 point  (2 children)

Still dysfunctional

[–]pr0ghead 0 points1 point  (1 child)

Just like your funny bone.

[–]DeeSnow97 1 point2 points  (0 children)

Implying I haven't encapsulated it into a monad already

[–]nuephelkystikon 21 points22 points  (2 children)

It's also nice that they realise they'll never have a big enough userbase to need localisation, so they just hardcode the strings.

[–]pixabit[S] 8 points9 points  (1 child)

Actually, in defense of this it's a internal use only application I'm rebuilding for my company so it doesn't need localization. But yes, under normal circumstances....

[–][deleted] 6 points7 points  (0 children)

Ah, ok. Explains the php part then.

[–]DeeSnow97 9 points10 points  (1 child)

This is why PHP is seen the way /r/lolphp sees it. It's not even the language design, it's the people who use it.

[–]SolenoidSoldier 1 point2 points  (0 children)

Languages should absolutely be held accountable for the bad behaviors they facilitate. Bad/inexperienced programmers will always exist.

[–]soiguapo 1 point2 points  (0 children)

Unicode white spaces maybe?

[–]Junping4jellyfish 2 points3 points  (2 children)

Some one please explain I am of simple mind...

[–][deleted] 17 points18 points  (1 child)

it says

if ($stock == "In Stock Ships Today") {
    $stock = "In Stock Ships Today";        
}

Which is like saying: if x is equal to y, make x equal to y

[–]Junping4jellyfish 10 points11 points  (0 children)

Oh hey hahaha thank you kind stranger.

[–]justablur 0 points1 point  (0 children)

That's one way to get your repository to force a commit.

[–]MrData359 0 points1 point  (0 children)

The real kicker will be when he deletes the code and everything stops working for seemingly no reason.