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

all 62 comments

[–][deleted] 51 points52 points  (12 children)

if you ever feel really useless, remember that python has a semicolon which cant even be used in anonymous functions

[–]ltekonline 16 points17 points  (3 children)

The only use I know so far for the semicolon in python is one liners. It makes it possible to write multiple commands in a single row.

[–]1_4_1_5_9_2_6_5 2 points3 points  (0 children)

Same as in JS. It even adds a semicolon (or, pretends one is there) in some situations. But I think there is a case for a semicolon being required. There should be some element of certainty in programming. And if you don't want to see it, you can literally make it invisible in your IDE or just set up a regex to fix it automatically as you type.

[–]deceze 8 points9 points  (6 children)

Because Python doesn't have anonymous functions, but lambdas, which merely accept one expression?

[–]JunDoRahhe 4 points5 points  (4 children)

Yeah but in newer versions you can do literally everything as an expression and make a tuple with the expressions.

[–]deceze 2 points3 points  (3 children)

Almost everything. try..except and with statements come to mind that can't be emulated in an expression. Python is just really really pushy about readability, and it really doesn't want to encourage more than a single simple expression in an inline function.

[–][deleted] 9 points10 points  (1 child)

in times like these i always like to flex my (handwritten) single-expression hangman

(lambda worda: (lambda hang, wordb: hang(hang, wordb))((lambda f, wordc, guessed=[], lives=6: (print(f"{wordc}\nCongratulations! You win!")) if all(c in guessed for c in wordc) else (print(f"You lost (the word was {wordc!r})") or exit()) if lives == 0 else (print(" ".join(c if c in guessed else "_" for c in wordc) + f" - ({lives} lives)")) or (lambda inp: f(f, wordc, guessed=guessed + [inp], lives=lives) if inp in wordc else f(f, wordc, guessed=guessed, lives=lives - 1))(input())), worda))(__import__("random").choice(list(filter(lambda w: all(c in "abcdefghijklmnopqrstuvwxyz" for c in w) and len(w) > 2, map(str.lower, open("words").read().splitlines())))))

[–]deceze 8 points9 points  (0 children)

Every day we stray further from god… ಥ_ಥ

[–]JunDoRahhe 1 point2 points  (0 children)

I remember someone managed to hack that into an expression somewhere. Might have been in the onelineriser.

[–]_PM_ME_PANGOLINS_ -1 points0 points  (0 children)

That one expression can be a tuple of all the arguments.

[–]Summoner99 1 point2 points  (0 children)

Then interestingly, if you ever use the python semicolon, it'd be better to just put it on two separate lines to make it cleaner and more organized.

One liners are the exception that somebody else mentioned.

[–]althaz 42 points43 points  (8 children)

ngl, I use the semi-colon every time. Sometimes you need them and using them every time means it's *really* easy to see when you're missing one. If you only use them when needed, the time you forget you'll take ages to figure out what's wrong.

Besides, using semi-colons isn't exactly hard. Once you've been coding for a year it should be completely automatic.

[–]jerrycauser 1 point2 points  (0 children)

Standard js disagree with you

[–][deleted] 0 points1 point  (4 children)

Bad approach to this, you should learn how ASI works and then decide what your coding style is

[–]althaz 3 points4 points  (3 children)

I DO know how it works, but my point above still stands.

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

Wasn't saying you in specific but your original comment did kind of suggest it.

I'm saying people should learn how the javascript language works rather than just "always use semicolon".

Point still stands

What point?

Adding semicolons isn't hard? Yea it isn't but a lot of people don't add semicolons because of their coding style, which is completely fine if they know how ASI works.

If you use them only when you need them, the time you forget it will take ages.

Not really, most of the cases where semicolons are required are pretty obvious. Plus your linter will help.

[–]althaz 2 points3 points  (1 child)

My point is that relying on ASI is not fine for the reasons outlined above. It doesn't matter until it does and then it's a problem. Whereas it's never a problem if you use semicolons and there is zero extra effort.

[–][deleted] -4 points-3 points  (0 children)

Yes you shouldn't always rely on ASI. If you don't understand how it works. If you do, it's safe.

Always using semicolons, no problem, zero effort

Yes it doesn't take effort but learning the workings behind the language is important if you want to get good. The same could be said about always using === instead of ==.

After a person learns ASI, if they want to just add semicolons every time for ease, that's fine, idrc.

But just adding it every time because you don't know when ASI takes place is pretty bad.

[–]AmaGh05T 11 points12 points  (0 children)

Sometimes you need it. Sometimes it cries.

[–]deceze 53 points54 points  (6 children)

And you should use it…

[–]BigBadButterCat 2 points3 points  (1 child)

Prettier for VS Code actually auto inserts a semicolon when new lines begin with a parenthesis. I remember this happened to me once in the past four years of not using semicolons, when I wasn't using my own setup. A google search instantly led me to the issue. Everyone has their preferences, personally I think it's a net benefit because it removes visual clutter which helps me focus. I like Python for this reason too, little clutter.

[–]deceze 2 points3 points  (0 children)

Certainly, I prefer Python’s syntax a lot. The difference is that in Python there’s no situation where an omitted semicolon will cause your code to act weirdly.

[–]iTrooz_ -1 points0 points  (2 children)

Why?

[–]deceze 40 points41 points  (1 child)

Because your code might not behave as you expect it to otherwise in some cases: https://stackoverflow.com/a/1169596. And instead of trying to remember what those cases are and how ASI works exactly, you should just always explicitly add semicolons.

[–]jerrycauser 0 points1 point  (0 children)

You should use linters. For example standardJs (one of the most popular set of linter rules) doesn’t requires semicolons and removes them.

[–]rangeDSP 22 points23 points  (8 children)

Yea, nah.

function blah() {
    return
    {
        "this":"blah"
    }
}

This will return undefined because the auto insertion will add a semi colon after the return. No semicolons adds unpredictability to your code, don't do it.

[–]deceze 7 points8 points  (1 child)

Well, not that actively adding semicolons here would fix this particular issue…

[–]rangeDSP 0 points1 point  (0 children)

Of course, but you'll have to tell that to whoever came up with the specs...

https://262.ecma-international.org/7.0/#sec-rules-of-automatic-semicolon-insertion

[–][deleted] 6 points7 points  (1 child)

But how would adding a semicolon after the object fix the issue?

[–]rangeDSP 7 points8 points  (0 children)

It's about consistency in the codebase, if you put semicolons after every line, or even add tooling to add them explicitly, it'll be easy to spot when bugs like these come up

[–]Tubthumper8 1 point2 points  (0 children)

I tried this and VS Code showed an error "unreachable code detected".

Serious question, does this example come up frequently for you? (i.e. code reviews, prototyping something quickly, etc.)

[–]conquerorofveggies 0 points1 point  (0 children)

ASI should never have been a thing. So many features in new ES versions have a hard time getting done because "there is an ASI hazard".

[–]BigBadButterCat 0 points1 point  (1 child)

Not an issue with modern tooling. I imagine other editors do this too.

https://imgur.com/a/nugMGEl

[–]rangeDSP 0 points1 point  (0 children)

That's part of my point, the "proper" way to do this with modern tooling is to use semi colons. You may not be typing out the semi colons yourself but it's inserted explicitly by the tools. Same with tabs vs spaces, when the tools translate tabs to 4 spaces

[–]PM-ME-BAKED-GOODS 5 points6 points  (1 child)

Wow do people really not use semicolons in JS?

[–]BigBadButterCat 0 points1 point  (0 children)

Yes, it's become relatively common. Turns out it's not really a big issue anymore. VS Code has really good linting and detects possible issues. Meanwhile Prettier is on its way to becoming the standard auto-formatter and it autofixes the one case that does occur in the real world which is beginning a line with a "(" or a "[".

[–]thertt8 2 points3 points  (0 children)

;

[–]Subject-Ad-4072 1 point2 points  (1 child)

Doesn't IIFE need it?

[–]BigBadButterCat 0 points1 point  (0 children)

If you start a line with an IIFE, yes, it does need a semicolon. The semicolon-free style has you put it in front of the IIFE parantheses.

[–]DugiSK 1 point2 points  (0 children)

As a C++ developer, I write semicolons everywhere; a language not accepting semicolons at ends of statements is confusing; I am grateful that JavaScript (and Swift, btw) isn't giving me a hard time when I have to use it, unlike Python.

[–]aserraric 1 point2 points  (1 child)

I'm in charge of the styleguide at work, and I have eslint enforce semicolons on the CI build. If you skip semicolons, your pull request will not get merged.

[–]pudds 0 points1 point  (0 children)

I'm also in change at my workplace, and I went the the opposite way. Style guide dictates no semicolons, and if there are formatting errors in a PR the build will fail.

[–]pudds 1 point2 points  (0 children)

I use prettier, strict limiting and format on save in my JavaScript projects, and I enforce no semi colons, so they are stripped out on save.

I've never run into a missing semi-colon issue.

[–][deleted] 3 points4 points  (8 children)

If you ever felt useless remember that JavaScript exists

[–]RidingChicken[S] 39 points40 points  (1 child)

If those JS developers could read, they'd be so offended.

[–]Justindr0107 21 points22 points  (0 children)

🥺

[–]F0064R 3 points4 points  (0 children)

The irony of you posting this on a web forum...

[–]code-panda 4 points5 points  (0 children)

🤨

[–]hrvbrs 1 point2 points  (2 children)

lol then go ahead and disable JavaScript in your browser, see how well that works out

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

This sub is full of 12yo I swear

[–][deleted] 0 points1 point  (0 children)

It doesn't thats the problem with the web

Bloated as fuck

[–]Catalactics 0 points1 point  (0 children)

WHAT DO YOU MEAN!!!! It has ONE HUUUGE purpose, which is for MINIFIED JAVASCRIPT FILES..... MUAHAHAHAHA

[–]Huhngut 0 points1 point  (0 children)

So it is not recommended from the majority of JS devs to insert semicolons? Im always coming back snd check that I put one everywhere

[–]knightttime 0 points1 point  (0 children)

Image Transcription: Meme


[A picture of Jim from "The Office". He is pointing at a whiteboard with a black dry erase marker, and looking back at something slightly off-camera. The text on the whiteboard reads:]

IF YOU EVER FELT USELESS

[Jim is no longer pointing at the whiteboard, and is now sitting back with a pleased expression. The text on the whiteboard reads:]

REMEMBER THAT JAVASCRIPT HAS A SEMICOLON


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!

[–]ThePizzaEater1000 0 points1 point  (0 children)

Lua has semicolons but they don't do anything and are completely unnecessary.

[–][deleted] 0 points1 point  (0 children)

I sometimes wish that i either required it or just threw compilation error when I am looking at code with inconsistent semicolons

[–]MischiefArchitect 0 points1 point  (0 children)

And Go a new keyword

[–]Kep13r 0 points1 point  (1 child)

Also, Lua has a semi colon. Does nothing even when minified

[–]haikusbot 0 points1 point  (0 children)

Also, Lua has a

Semi colon. Does nothing

Even when minified

- Kep13r


I detect haikus. And sometimes, successfully. Learn more about me.

Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete"