DEV Community

Discussion on: VS Code - You don't need a formatting extension (Prettier and friends)

Collapse
 
danwalsh profile image
Dan Walsh • Edited

I tend to disagree that there is little to no effort in manually formatting your code. In my own experience, formatting code takes up precious cognitive load that I'd rather spend working through my code logic.

For example, I know I want to:

  • Terminate each line with a semicolon
  • Use four spaces per indentation, and
  • Wrap all arrow functions in curly braces

All of the above are just personal preferences, but I don't want to have to think about any of this. Instead, I want to focus on converting business logic into coding syntax, and having to pause every few moments to throw in an arbitrary semicolon or fix the indentation of an entire block just takes me out of "the flow".

I'd suggest taking the extension settings a step further—configuring Prettier not only to auto-format your code on save, but to also display formatting suggestions inline using yellow wiggly underlines. That way you have the benefit of learning why a formatting rule is getting applied, as well as the auto-format on save. You get the learning plus the time savings.

You mention in a later comment that:

For me, when coding, especially javascript, it helps to do the formatting myself because it also helps me "see" the "scope" of my methods and classes, so my brain can quickly spot where a scope starts and ends, also helps me make less mistakes when creating new objects, or modifying existing stuff.

Again, I'd argue that extensions like Bracket Colorizer (which is now a built in function of VS Code) helps immensely with block scope visibility.

Lastly, your comment regarding "complex tasks" in relation to web dev is quite dismissive:

Now depending on what kinda coding/programming you guys do, i understand the "focusing on more complex tasks", but really, i've been doing this 16 years myself and in web dev there are few things that i would call "complex tasks".

Complex tasks come in all shapes and sizes. They can be laborious and intensive, such as refactoring a legacy component for use in a newer framework. They can be more investigative, such as debugging a complex pipeline build issue with Webpack. Or they might have nothing to do with the code at all, such as having to sporadically context switch between development tasks, support tasks, meetings and the other umpteen distractions flowing through the door. All of these things have something in common—they take up precious cognitive load and focus. Adding manual code formatting on top of that seems like an extra burden to me.

Work smarter, not harder. 🤓

Collapse
 
ravavyr profile image
Ravavyr

Great response.

I still avoid Prettier like hell, because working for an agency i have to work with client code across various platforms, codebases, often in different languages, etc etc. Worse, some clients enforce their own rules like "standards js" or some other configurationg for formatting that i have to follow.

Getting yelled at by "avoiding insulting people here" because my formatting didn't match their is low on my list of things i like, so i look at the code i'm editing and make my changes match as best i can.

Funny thing, in some cases i make my formatting absolutely different on purpose because I want to come back later and go "This is my code, that is not my code" especially in really old applications that i have to still support, or when clients get to be a pain and nitpick every bug as "you made a change last week, this is your fault". Anywho, that's a different discussion altogether.

You're right, i was being dismissive with the "web dev is easy" bit.
Frankly, I'd say 99% of what we do is easy, once you've gotten good at it, or maybe it's "once you've seen enough bugs to recognize them before you know the details"
There are times when bugs stump people and can take days to resolve, but those are few and far between.
The industry is largely people with less than 10, or less than 5 years exp and a lot of things seem hard during those years, but with enough experience i think most of it is pretty damn easy.

eg. Centering a div is a nightmare for newbies, but a year or two in, you copy paste a solution you've used fifty times before and don't even think about it.
In JS you can say arrays and loops are hard when you start, but a few years in and you don't even think twice when using the various looping methods and you've realized everything is an object.
In PHP handling session variables, setting cookies, writing crons all seem complex, until you've done em a few dozen times.

As for VSCode extensions, i'd recommend checking out "indent-rainbow" , "power mode" for fun, and "indented block hightlighting". And yea the bracket colorizing they added is nice and useful.

I try to work smarter not harder :)
Whenever I get to code from scratch i write it as simple as possible with the goal being "Me or anyone else has to understand this 6 months or a year from now".

I avoid tools because the way i code hardly requires them. My frontend code requires no build tools, to deploy i use github actions, to debug i run the web pages, use browser dev tools, check the network tab and look at the console log. For backend i've got my server error logs configured and usually SSH in and go
"tail -20 /var/log/apache2/error.log" and fix whatever pops up in there.

I really think web dev has been made overly complex by implementing more and more "programming" things that work well for desktop applications and computer programs, but have only added weight and bloat to the web. Things it's never really needed. But again, that's a discussion for another time.

Have a good day :)

Thread Thread
 
pavelloz profile image
Paweł Kowalski • Edited

Getting yelled at by "avoiding insulting people here" because my formatting didn't match their is low on my list of things i like, so i look at the code i'm editing and make my changes match as best i can.

Usually .prettierrc and/or .eslintrc files take care of that.
I always say: i dont care whats the code style, as long as its standarized and everyone has a software that does it for us (ie. no manual labor and thinking involved)