Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What, seriously, the names of your variables matter? And this is seen as a good thing?


Absolutely they do. That's the major benefit of object orientation: named properties and methods.

Otherwise, we fall into exactly the "boolean trap" that the author links away to. [1]

[1] http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-t...


properties and methods, yes. But I am not familiar with any other object-oriented language (is JS one now?) where the names of local variables matter. I mean, is 'local' even the right word, when the names chosen as references have semantic impact outside the local scope?


I'm not sure why you think local variable names are mattering here...

What's happening is that this expresion:

    const { error, value } = obj;
where obj is an object will assign obj.error to error and obj.value to value.

You could name your locals something else if you wanted, of course:

    const { error: myError, value: myValue } = obj;
will assign obj.error to myError and obj.value to myValue. There just happens to be a shorter syntax for the common

   const { error: error, value: value } = obj;
case.


Ah, it's a slice, I get it now, thanks.


Right, they don't, and they shouldn't. If I'm not mistaken, we already agree completely.

I'm saying that functions should return either primitives or objects that have properties (or keys, since in JS all objects are just hashmaps) that uphold some appropriate abstraction, completely separate from whatever the variables might have been called inside the function body.

For example, the return object from some function `getDate()` might have a .year property, or .toUnix method, etc.

If all I'm given is an array of arbitrarily typed values, I have solely the array indexes and values (or to go to the docs or implementation) to clue me into the semantic meaning of what was returned.


{ error, value } is a shorthand for { error: error, value: value }. Rust has an exactly same feature.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: