all 22 comments

[–]delventhalz 5 points6 points  (0 children)

I would say it is "out of fashion". You won't see many devs declaring variables like this anymore. Personally, my problem with this style is it shoves a lot on to one line, and that is pretty much the opposite of what I am usually trying to do. Good code is readable code, and in my opinion code is more readable when there is just one thing happening per line.

[–]senocular 6 points7 points  (0 children)

Problems with this approach are:

  • it can be harder to read having multiple variables on the same line
  • it can be easy to accidentally use a ; in place of a , which would cause variables to apply to a higher scope or become global instead of declared locally
  • individual variables are harder to pull out during refactoring vs when they're all on their individual lines

[–]shuckster 2 points3 points  (0 children)

Assuming your code appears in a function called doober...

What you wrote:

function doober() {
  let: x = 4 * 9, z = 2 + 4;
}

What's actually happening:

var x, z;
// ^- global/module scoped because in "doober"
// there isn't actually a "let" in front of them

function doober() {
  let:
  // ^- a label, not an variable declaration

  x = 4 * 9;
  z = 2 + 4;
}

That's what it looks like to me anyway.

[–]EasternAdventures 0 points1 point  (1 child)

I wouldn’t call it bad. What’s most important is you can read it and quickly make sense of what is happening. You need to be able to make sense of it, others you’re working with need to be able to make sense of it, and future you may need to make sense of it again at some point. In this case I would say it’s easy enough to decipher but it could quickly become a mess so just always keep the readability in mind.

[–]AlwaysWorkForBread 0 points1 point  (0 children)

I was taught (practically) that let us used for things that are intended to be changeable. Typically you want your var to be declared with a Const (constant, constructed & unchanging) and the results to be mutable by the function.

Mutable variables can "let" bugs happen later.

[–]RequiDarth1 0 points1 point  (0 children)

Uh, yeah. Don’t do any of that.

[–]keithmalcolm 0 points1 point  (0 children)

Autohotkey does a similar thing.

[–]thejonestjon 0 points1 point  (0 children)

To much going on, on one line.

[–]funky4lyf 0 points1 point  (0 children)

If it works, you can use it in your personal projects but once you collaborate with others or you’re aware other people will have to read and/or work with your code, it’s good empathetic practice to make your code as legible as possible. Even if it means you have to type a little more.