r/learnjavascript • u/TotalOrion • Mar 13 '22
I made an extension that comments your JS code for you
14
u/LEDThereBeLight Mar 14 '22
Really cool. Regardless of how much utility you actually get from it (I agree with the other comments, they seem largely redundant - I'm sure this is a very hard problem to solve), this is a really interesting and impressive project. How are you implementing it? Is it some sort of AST reduction algorithm that pattern matches out the reduced form of an expression and makes some sort of conclusion based on what the reduction looks like?
6
3
3
u/physioboy Mar 14 '22
I think this is super cool, regardless of the level of utility it provides. Very neatly done!
2
u/pmw57 Mar 14 '22
Sorry, but automatically generated comments cannot be trusted to be correct. And, you cannot be sure that they are correct unless you carefully examine the code, which you are much less likely to do when using an auto generator.
1
1
0
-8
u/yadoya Mar 13 '22
Why use this when you have Co-pilot?
7
u/Avi_21 Mar 13 '22
why use co-pilot if you know how to write code...
1
0
u/hanoian Mar 14 '22
It makes me a lot faster, and the way it builds up knowledge of your entire application is extremely convenient. I don't think it's possible to use it and the take away to be "Why use it if you know how to write code" so I'd recommend trying it.
1
u/Avi_21 Mar 14 '22
But then you stop using your brain, and will rely too much on it, no?
1
u/hanoian Mar 14 '22
I don't use it when I'm actively learning something new. Like when I was learning some Typescript and GraphQL. But when it's just normal code, I use it.
No, it wouldn't make me forget, and I still have to prompt it and know where to go. It doesn't add code all over a project by itself.
0
Mar 13 '22
[deleted]
5
u/_meshy Mar 14 '22
It reminds me of a fresh CS grad at their first job.
2
u/ItsWaryNotWeary Mar 14 '22 edited Mar 14 '22
I work with a (50yo+) guy who does this
# create a new foo val fooObj = FooObj(bar=true) [...] # return the foo return fooObjOh and he uses separators like this ########CONSTANTS###########
# set the value of constants val BAR = "" val BAT = "" ########FUNCTIONS########### # some comment explaining what the function does even though it's clear as day in code fun fooBar() {...} # some other useless noise fun batBaz() {...}0
Apr 07 '22
[deleted]
1
u/ItsWaryNotWeary Apr 07 '22
Comments should generally only be used to explain why, not what. Why is this logic here, why do we need it, etc. Sometimes you have to do something janky to get around a bug in a dependency or handle a weird edge case or something - use comments to explain that.
Explaining what the code is doing pointless. Whoever is reading can just read the code. Comments that just restate what the code is doing are noisy, they add to the mental load. Plus it's very common for comments to never be updated, even when the code is updated. So you'll end up with comments explaining logic that has since been changed.
And the separators and loud labeling makes the code itself harder to digest. Just don't add more text to your code than is required for someone to understand.
1
u/og-at Mar 14 '22
Ok so I used an in-dev client for my other comment and it apparently dropped most of the message 🤣
True. Except . . .
You don't have to use it for every function. Use it for the complex functions or statements that are probably hard to decipher at first glance.
All things in moderation.
0
10
u/TotalOrion Mar 13 '22
Check it out at https://readable.so