this post was submitted on 22 Nov 2025
655 points (98.7% liked)

Programmer Humor

29572 readers
1597 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

cross-posted from: https://lemmy.ml/post/39334581

you are viewing a single comment's thread
view the rest of the comments
[–] SpaceCowboy@lemmy.ca -5 points 2 months ago (15 children)

Yeah for whatever reason, FE devs want to make everything a const. It's like a religious belief or something, it's really kinda weird.

const fun = () => { const something = "whatever" const array = []; array.push(someting)

for (const thing of array) { if (thing === 'whatever') blah(thing) } }

Semicolons? Optional. Which quotes you should use? Whatever you feel like! But you must declare things as a const wherever possible! Even if it's an array that you're going to be changing, declare it as a const because you should know that you can push things into a const array, and since it's possible to declare it as a const, you must declare it as a const.

Why is this? Nobody knows, but it's important to FE devs that you use const.

[–] brian@programming.dev 2 points 2 months ago (9 children)

semicolons? quotes? use a formatter and don't think about it. I think js world has basically done this already.

const is simpler. why would I declare an array as let if I'm not reassigning? someone can look at it and know they don't have to think about reassignment of the reference, just normal mutation. ts has the further readonly to describe the other type of mutation, don't abuse let to mean that.

const arrow over named function? gets rid of all the legacy behaviors and apis. no arguments, consistent this, and no hoisting or accidental reassignment. the 2 places you should ever use named fn are generator or if you actually need this

[–] mr_satan@lemmy.zip 1 points 2 months ago (2 children)

semicolons? quotes? use a formatter and don't think about it. I think js world has basically done this already.

It's nice when a codebase has sane formatter conventions. I can't say that my workplace does, tho…

const arrow over named function? gets rid of all the legacy behaviors and apis. no arguments, consistent this, and no hoisting or accidental reassignment. the 2 places you should ever use named fn are generator or if you actually need `this

How is having arguments and this an issue? If one doesn't need them, then it can be just left unused. I really don't get this argument. It makes everything visually a variable. I see no benefit to this convention and actively despise it.

[–] brian@programming.dev 1 points 2 months ago (1 children)

I've worked at several places that didn't have formatters when I started. they did by the time I left. you can incrementally adopt them and if it's automated most people at worst don't care. advocate for things you want

reassignment and hoisting are the significant ones. behavior around this does just seem more intuitive than otherwise when it comes up, so I think telling especially new devs to use const arrow fn everywhere but classes is a reasonable rule

hate to break it to you but it behaves like a variable either way. function just behaves closer to a var variable. const fns are less like variables since no assignment. intellisense/devtools all show them just fine. it really is just a minor aesthetic difference on the definition

[–] mr_satan@lemmy.zip 1 points 2 months ago

I've worked at several places that didn't have formatters when I started. they did by the time I left. you can incrementally adopt them and if it's automated most people at worst don't care. advocate for things you want

We use formatters, I just disagree with our current conventions (nitpicky, I know).

hate to break it to you but it behaves like a variable either way. function just behaves closer to a var variable. const fns are less like variables since no assignment. intellisense/devtools all show them just fine. it really is just a minor aesthetic difference on the definition

To me it's about readability and declaring everything as const goes against that.
What benefits does it have? Using this in arrow functions is still valid it's just that they will use parent scope to resolve it. You saying it doesn't have this or arguments doesn't convey any benefits (nor real drawbacks) to me. Hence the convention feels useless at best.

load more comments (6 replies)
load more comments (11 replies)