re: Compact or Verbose Codestyle? VIEW POST


I'm not a js developer, but I would use this middle ground (hoping it actually does the same thing) :

const get = (store, key) => {
    if (!Reflect.has(window[store], key)) {
        throw new Error(`Key "${key}" not found in window.${store}.`);

    return JSON.parse(window[store][key])

I was going to make a similar code suggestion, the variables at the end don't add anything.


Well, one little use case of the variables for newbies: easier to debug (slide in a console.log(var) easily).


One thing you get from The verbosity of the ending variables, is that you don't have to break apart the line to debug the code. You could identify whether your bug resides in the JSON parse or the store getter without changing any lines of code.

I think generally, developers are more comfortable compacting things we understand well, especially when they are stable and behave in expected ways (like JSON.parse and window.localStorage).

I believe I observe people compacting calls to their own code more often, (because they understand it well), and use more verbosity calling their peers' code (because they understand it less).

Personally I lean more towards universal verbosity for the ability to debug without changing lines of code. In my opinion, this also fosters self documenting code, especially when calling internal code and not common environment/library APIs.

code of conduct - report abuse