this post was submitted on 16 Aug 2023
662 points (90.7% liked)

Programmer Humor

32453 readers
345 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

TIL about the greek question mark

Tell me, can you tell the difference between these two characters?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 47 points 1 year ago (2 children)

Laughs in just removing all semicolons because it's not necessary in JS.

[–] [email protected] 4 points 1 year ago

Great, now you just need to do the rest of the code.

[–] [email protected] 3 points 1 year ago (4 children)

It is recommended. But in TS it is not necessary with rare exceptions.

[–] [email protected] 19 points 1 year ago* (last edited 1 year ago) (3 children)

That's what's really irks me be about JS--you can do just about whatever but you're not supposed to.

It's an imperative language, but best practices are to use it functionally.

You can omit semicolons, but best practices are to use them.

You can use sloppy equality, but best practices are to always use strict.

[–] [email protected] 18 points 1 year ago

JavaScript reminds me of an older brother who happens to be the most laid back stoner you could meet. "Like yea man, you should probably use semicolons, but I ain't gonna narc"

[–] [email protected] 9 points 1 year ago (1 children)

After switching to typescript with linting and prettier I simply hate writing vanilla JavaScript anymore. Some people complain about the extra project setup needed but I find that time pays for itself immediately.

[–] [email protected] 0 points 1 year ago (1 children)

Extra project setup like pnpm add -D typescript && tsc --init? One thing that is kinda annoying is that you have to manage were will js files go.

[–] [email protected] 2 points 1 year ago (1 children)

And eslint and setting up tsconfig for your project structure.

[–] [email protected] 0 points 1 year ago (1 children)

You don't need eslint with TS.

[–] [email protected] 1 points 1 year ago (1 children)

Why do the typescript extensions to eslint exist then?

[–] [email protected] 1 points 1 year ago (1 children)

I don't know. I never used eslint, therefore it is not needed. Everything works perfectly fine without it.

Why do you need it?

[–] [email protected] 1 points 1 year ago (1 children)

Same reason you use typescript. It helps you catch bugs and follow programming best practices. You also don't need typescript, but with it your code is better. Typescript is technically just a really fancy linter. The actual compilation mainly just removes the type data and does some JavaScript engine compatibility.

[–] [email protected] 1 points 1 year ago (1 children)

So why there are typescript extensions for eslint if both are linters for JS? You should either use eslint with JS or transpile TS to JS, right?

Are there bugs in TS that eslint can catch?

I personally never seen TS project with eslint.

[–] [email protected] 1 points 1 year ago (2 children)

Typescript compiler enforces language requirements, the linter enforces language best practices. Best practices help you avoid bugs.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

Ok, I should check it out, then. Maybe I already follow all the best practices, so I wouldn't need it anyway. ;)

[–] [email protected] 2 points 1 year ago

I try and follow best practices always too, but when the linter is catching it for you it's less to think about so you can focus on the important parts of the problem

[–] MotoAsh 8 points 1 year ago (1 children)

You need to remember that a lot of those best practices are to cover for the performance issues from misusing loosely typed variables.

The JavaScript engine can compile clean, type-safe code down to be almost as fast as properly compiled code. When you use various features like the loose equals or various object mutations and the like, the engine cannot optimize it, leaving your code much, much slower.

[–] [email protected] 5 points 1 year ago (1 children)

I'll add that to my mountain of reasons for using typescript

[–] MotoAsh 3 points 1 year ago

Yup! I love TypeScript, and I love the flexibility of JavaScript. With all of the type templates and generics and other black magic TypeScript has, it's pretty easy to even support the crazy stuff like mixins and contextual parameters (if I'm not speaking too loosely while avoiding proper terms!).

A lot of the crazy stuff won't optimize, but at least it goes to show how it's not really tying JavaScript's hands even when requiring TS everywhere.

[–] [email protected] 4 points 1 year ago (1 children)

thanks to eslint enforcing it in the default rules it's necessary for most typescript projects

[–] [email protected] 4 points 1 year ago (2 children)

Except that you should use Prettier for formatting instead of ESLint. That said, semicolons are useless noise

[–] Korne127 2 points 1 year ago (1 children)
[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

It adds even more auto formatting rules so you can basically stop thinking about formatting entirely. I used to be opinionated about formatting but now I just go with whatever prettier does. It's not always the best but it's consistent and it's a big chunk of my brain I can free up for things that matter. It also formats things safely so you don't run into those weird edge cases where semicolons matter if you choose to turn them off.

[–] MotoAsh 3 points 1 year ago (1 children)

Aren't some of the scenarios for needing a semicolon logical-domain problems and not syntax issues? I wouldn't trust autoformatting to spot a logical problem, though I also hope no one is writing code that flippantly. (as if honest mistakes aren't common enough!)

[–] [email protected] 3 points 1 year ago

Maybe there's some edge case but in my years of using prettier I haven't encountered one once.

[–] [email protected] 1 points 1 year ago

Never used eslint. prettier is a must. semicolons are only needed to split some rare TS syntax lines.

[–] [email protected] 4 points 1 year ago (2 children)

I wouldn't do it without an auto formatter. With prettier it will catch potential no semi colon issues.

[–] [email protected] 1 points 1 year ago

You absolutely have to use prettier with JS. I don't think there is auto adding missing semicolons in C/C++ though, it would be very useful.

[–] [email protected] 0 points 1 year ago

I tried prettier and I thought it was literally making my code uglier. It's eslint --fix for me.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

Yes, true. I also did setup so that any missing semicolon will be added, because I got sick of not inserting them sometimes and then some code was without them and some was. (Before I tested just leaving them all out, out of fun, so I got into the habit of just leaving them out regularly)