r/shittyprogramming • • Jul 19 '17

Wrote this documentation a long time ago. 10/10

Post image
326 Upvotes

43 comments sorted by

22

u/tangerinelion Jul 19 '17

TIL JavaScript has optional semicolons. Thanks extremely useless comment!

28

u/Raknarg Jul 19 '17

TIL JavaScript has optional semicolons. Thanks extremely useless comment!

But not always

3

u/LEGOlord208 Jul 19 '17

It's optionally optional?

3

u/Zackeezy116 Jul 19 '17

I read in a JavaScript book that it isn't so much optional as JS guesses where you meant for it to be and adds it at runtime. It isn't always sensical.

Like, the example they use is that if you do:

x++
y

Then it will add the semi colon before the increment operator, making the code equivalent to

x;
++y;

2

u/LEGOlord208 Jul 19 '17

stopad js, just treat newlines like you treat semicolons

2

u/Zackeezy116 Jul 19 '17

That would be great except then you wouldn't be able to do stuff like

document.getElementById("submit").addEventListener("click",function(){
    //do some things
});

You'd have to have it all on one line, otherwise add really complicated guessing games. The real take away here is if you're going to make semi colons optional, also make white space matter.

2

u/LEGOlord208 Jul 19 '17

Pretty sure that will work anyway since a useless semi colon should be treated as nothing. The problem is if statements without a block (if (foo);/*<-*/bar()).

3

u/Zackeezy116 Jul 19 '17

The moral of the story is JavaScript is really strange.

4

u/LEGOlord208 Jul 19 '17

JS is pure evil

3

u/Zackeezy116 Jul 19 '17

I like JS. It's powerful, and it's portable with easy gui support. I can write a JS app and send it to my friend and not worry that his computer can't run it. But when it comes to writing JS on a large scale, I have to imagine there would come a point where you'd wonder if it would be easier to write in something else, but then you remember that front end basically only supports JS as a programming language... and you cry

→ More replies (0)

5

u/Raknarg Jul 19 '17

Sometimes it changes the interpretation of the line

2

u/tmewett from The Cloud™ Jul 19 '17

Operation, opposition, off not optional, out-of-sight, out-of-mind, wide-beaming opticals

16

u/poop-trap Jul 19 '17

Here's an example for OP before he commits to the idiotic hell of implicit statement termination...

This:

var imSoEdgy = function(bro) {
  return bro
}

// haha the above terminated right?
(function(window) {
  return window.hipsterriffic || 'dumbass'
})(this)

Will not result in an imSoEdgy function and some code executed in a closure, but will call the anonymous function passing the result of the closure in as the bro argument assigning 'dumbass' to imSoEdgy.

There are plenty other examples of moronic gotchas too.

tl;dr use semicolons

3

u/Kutsan Jul 19 '17 edited Jul 19 '17

Solution is that never start a line with (, [, or `. If you really want that you can insert the semicolon before these characters. Like that:

;(function(window) {
  return window.hipsterriffic || 'dumbass'
})(this)

Most of time, semicolons are useless. If you learn how ASI (Automatic Semicolon Insertion) works, you are fine.

11

u/poop-trap Jul 19 '17

Found the hipster!

Implicit is never better than explicit when it comes to good programming practices. Just ask the creator of Javascript. The functionality is there because Javascript was originally written to be as robust to programmer error as possible, so that when Hacky McHackerson wrote his first browser script to make sparkles trail the cursor it was more likely to work than not. A good programmer programs correctly, not saves a few key strokes to show off or so that their beautiful minimal code matches their bare apartment that remains unfurnished because their last four startups never took off.

3

u/nodealyo Jul 19 '17 edited Mar 23 '18

Spamming is a really shitty thing to do. This script is one of the dumbest and spammiest scripts that I have ever seen. Did you know that no one cares about your mundane comments? You actually aren't even protecting any privacy because there are many sites out there that specifically cache comments just so that users cannot edit them. To reiterate, this script is shit and you should not be using it. Search for a different one, or edit it to say something less spammy. But in the end, it won't matter because we can still see whatever it was that you edited.

3

u/Kutsan Jul 19 '17

I'm saying that semicolon can't save you even if you use them everywhere. Just watch this or read this or this, I don't want to spend my time to explain to you how semicolon works in JavaScript. Mattias already did that.

2

u/fukitol- Jul 20 '17

You also get thoroughly fucked if you minify or uglify your code. Just use semicolons.

0

u/[deleted] Jul 20 '17

[deleted]

3

u/fukitol- Jul 20 '17

I'm not relying on some tool to ensure my code works.

5

u/[deleted] Jul 19 '17

Kind of. The comment is actually worse than useless because JavaScript "requires" semicolons for every statement, but also has something called Automatic Semicolon Insertion which makes them optional for some statements, but will also screw you over for some.

Just use semicolons.

-1

u/nodealyo Jul 19 '17 edited Mar 23 '18

Spamming is a really shitty thing to do. This script is one of the dumbest and spammiest scripts that I have ever seen. Did you know that no one cares about your mundane comments? You actually aren't even protecting any privacy because there are many sites out there that specifically cache comments just so that users cannot edit them. To reiterate, this script is shit and you should not be using it. Search for a different one, or edit it to say something less spammy. But in the end, it won't matter because we can still see whatever it was that you edited.

58

u/TuxGamer Jul 19 '17

The best part is that you did not describe what happens if you use href as a setter. Just what happens if you read from it.

5

u/fib0nacci112358 Jul 19 '17

More getters less setters?

32

u/d4rkshad0w Jul 19 '17

You didn't even use a multiline comment. Thats already shitty and I haven't bothered to read it yet.

8

u/LowB0b Jul 19 '17

The equal sign assign the variable on the left to the value on the right.

gr8 b8 m8

4

u/whelks_chance Jul 19 '17

I had to stop myself from commenting, glad someone else did.

4

u/TriCrose Jul 19 '17

Hey, you're the guy from that other thread who thought Rust is better than C++. It all makes sense now.

6

u/leetneko Jul 19 '17

This is a comment i stuck in a giant god class that i inherited (and still in the process of breaking down). Half warning, half fun.

1

u/marvin02 Jul 19 '17

Yeah, probably not indeed.

1

u/LEGOlord208 Jul 19 '17

Such an unesseccessery comment. I can spell "unezzesacry" just FINE >:(

32

u/[deleted] Jul 19 '17

[removed] — view removed comment

2

u/LEGOlord208 Jul 19 '17

And this was my original motivation behind making a program similar to look but looks for similar words instead...

41

u/hexane360 Jul 19 '17

One c, two s's

Necessary

46

u/maciozo Jul 19 '17

One collar, two sleeves

19

u/randomdude98 Jul 19 '17

Holy shit

15

u/[deleted] Jul 19 '17

Holy shirt

5

u/AlGoreBestGore Jul 19 '17

Holy shart

-1

u/RicardoPinheiro Jul 19 '17

Holy Jesus

FTFY

1

u/Cadabena Jul 19 '17

Never eat cheese, eat sausage sandwiches and remain young.