Oh, documentation. I'm working on open source software and I always get the feeling that no one ever wrote even the smallest piss of comments, aside from wet comments like
/**
* Returns id
* @return id
*/
public int getId()
I believe visual studio had a time where you'd see comments like this as they showed up when you referenced a method. Many IDEs have exceptions for information either in comments or brackets.
If you are using a cli to build your objects it will intentionally place all those on your get/set if it uses them.
Non-monospace docs? Sounds disgusting but to each their own //EDIT: just to make sure, I'm just joking, do whatever you want aside from making screenshots in light mode
More importantly it ain't that much of a hot take. Writing `wet` (wrote everything twice) comments is known as bad practice, similarly to smelly comments
I imagine it's like markdown where you could make keywords show in monospace. I think it's a neat idea I might look for a vscode extension to try it out.
The issue I have with light themes is not using them or some weird principle. When I'm working at night in dim light and I open a forum that should contain the answer to my problem but that answer is in a light mode screenshot, I'm losing my eyesight. I can only turn down my monitor that much
Js is required in this case. Its not like i get to pick the language. If its an COBOL Backend i have to write Cobol. If everything else is in js im gonna do js. If its c++ I'm gonna use that. Minecraft is written in java guess im gonna write my mods in java
Don't forget there are languages that compile to JS, so you don't necessarily have to use JS even if the end result has to be JS. I recently got the urge to dabble in the hellish world of browser extensions and I've been doing it via OCaml, a language I like already that has a JS output option.
The JS output is awful but it doesn't have to be. Since you presumably already know JS syntax pretty well you might like ReScript, which is a JS-like syntax on top of OCaml that produces pretty readable output. So you can get the nice stuff of OCaml and Reason like algebraic data types, great type inference, pattern matching, etc. in a JS-looking language that spits out pretty readable JS for you.
(I'd be using that one too but I prefer OCaml syntax and the ReScript people decided to stop supporting that in the future so I'm currently stuck with the gibberish that js_of_ocaml spits out. ah well)
I tested a little bit with an older version before the ReScript break (when it was still called BuckleScript) and the output was perfectly readable. Maybe not organised the way you'd do it writing JS directly, but it carried names over well so if there was a runtime error you could check the generated code and get a good idea of where the problem was in the original OCaml or Reason (or just ReScript now) code.
Can't say much more than that, since I was just trying to compare it to using jsoo so I didn't know what I was doing.
Anyway, it's a nice way to branch out because you also benefit from being able to transfer the knowledge to writing server-side (or desktop) native applications via OCaml or Reason. ReScript wants to diverge a bit to tailor itself more to JS use, but most of the features and benefits are still the same for all three and there's a lot of knowledge overlap.
In addition to reading the sites' documentation, it's worth checking out the Cornell course/book titled Functional Programming in OCaml. It's one of the best FP books I've read and it does a good job of teaching OCaml at the same time. And if you use this extension you can even do conversion from OCaml to Reason to learn with Reason or ReScript. :)
Plus F#, Clojure (via ClojureScript), Scala, and more. Though I'd rather write OCaml, F#, or Clojure than Kotlin personally.
The reason I named ReScript specifically, though, is you get the benefits of a really nice language (OCaml), but with an alternate syntax that reads/writes a lot like JS* and generates pretty clean output. For somebody that's using JS already that's potentially a great combination. Plus you can embed raw JS in a pinch, so you could incrementally convert existing code.
* This is helped by the fact that the type inference lets you completely omit type signatures, even in function definitions as well as elsewhere, in most cases so it tends to look like a dynamic language despite being statically typed. Sometimes it can't figure something out and you have to toss a signature on, but way better than having to annotate everything.
Well, if that's the case "I don't like my job", then you already know what to do. If that's the case "I'll write in whatevah language my company wants", then it's up to you to decide if you are ok with it.
I can't say what you should do. I can only tell you my thoughts. I would discuss the decision with managers, it doesn't make sense to force your dev department to write in every language in the world. Better to outsource this part of the project and create small maintainable microservice from it.
You shouldn't let people force you to do stuff you don't like. Your opinion and your life is important and it's up to you to decide what you want to do with your time.
Also, if you write the mod for say Minecraft and it has to be Java and you really really hate Java and you have to go through the mental breakdown on your cake day just to get the job done, then maybe it's time to relax a bit and ask yourself a question - does it worth it?
Yep. If developers had a choice they certainly wouldn't choose a moronic language like JS. Unfortunately this is what web devs are forced to use. TypeScript brings in a bit of sanity to this abominable language but it still boils down to JS.
If I have Reddit on my phone then a camera pic has far less steps to get a post than saving to my pc, transferring to my phone and then posting. That would make it the correct tool for the job
that combo launches the new snipping tool, which I don't really like to use. The old one is much better, as it shows you the image immediately after you snip. The new one you have to search it in your folder
It launches Snip & Sketch, which provides a system notification after you choose the region to ship and if you click the notification it opens the image for you.
A shortcut that lets you select a screen region and copies it to your clipboard for you to paste + provides a notification for you to optionally mark up the screenshot is more convoluted than launching a dated tool and fumbling with a GUI just to take a screenshot I’m gonna paste somewhere else and then get rid of? Sure.
In my first programming job, I noticed that the senior dev, who had 30 years of experience, never wrote comments. I asked him about this, and he told me that "good code is self documenting".
As it happens he also wrote by far the worst code I've ever seen before or since, so take his advice with a grain of salt.
This reads a lot like a smoker saying you shouldn't smoke because it's bad for your health.
"good code is self documenting"
The advice is sound. Comments do not make up for writing bad code. Your code should stand on its own in terms of legibility and intent. Achieving this is harder than writing bad code and commenting to make it understandable.
Treat comments as a necessary evil. Use them sparsely. For more on this I recommend Clean Code by Robert C. Martin.
Exactly this. Project after project I have come across stuff that I understand mechanically (notice I didn't say "logically", coz logic went out the window) how it works, but why the hell it was put in is a mystery. It doesn't make sense with the project specs. Was there a request along the way that necessitated this that was artfully logged to git as "made changes"? Of course if they didn't comment, there was no documentation updates (if there was any to begin with).
Even assuming you only write good, readable code where the logic is easy to follow, the code itself only explains the how; good comments should explain why it was done that way.
Months or years later, those comments are the ones that stop you from refactoring out some crucial bit of error checking or odd logic that is readable but seems pointless and, when removed, breaks everything.
Even if it's just for yourself it's good, because next year you might still be able to understand the code you wrote today but there's no way you're going to remember the details of why you wrote such a ridiculous kludge, so without those "why" comments you're going to think you were a complete moron for doing it that way. (Of course, you might think that anyway depending on the code, but at least you attempted to rationalise it to your future self)
Plus the next poor bastard that has to make updates to something you built originally won't be cursing your name wondering why you put some chunk of coding oddity in that makes no sense against the specs. You may have had a legit reason for it (some undocumented request) or you may not have known what you were doing (maybe you were making changes to something someone else prior built with no comments or documentation), but at least they'll know why you did it. I've made changes to code where I have explained why it was done, and noted how the existing code that I was working in didn't make sense to myself and others that looked at it.
sometimes, you shouldn't. even the 'why' can sometimes be explained in code. it's an art form in itself, and sometimes you do need comments, but I would argue that most code should be able to go undocumented and still be understood completely
so, ideally you would comment only the more obscure/weird code and all the kludges you write on the way, trying to explain not what it does, but instead how and why it does something, as it makes for a better image in your head?
so you would write something like "Send an email with Gmail API by getting token.json, doing some forbidden black magic with it, pack the message string into a Message object and send it" instead of just "Sends the provided string (argument 1) to the email specified (argument 2), also gets token.json"?
I would avoid taking programming advice on this sub tbh. It's generally not a good place for discussion, people come here to hang shit on other devs/frameworks/languages. By nature it's going to have a larger volume of toxicity and subjective opinions.
Commenting complex code is time saver for other devs that search something in you code. 100% faster reading a comment than the cleanest of the clean code, as long as the code is somewhat complex ofc
Good external documentation is gold. And where I work with older staff leaving and the remaining developers juggling multiple high-priority ( because isn't every project high-priority to the person demanding it), documentation was the first thing to suffer. We have lost three new hires in less than a year because they get thrown in the deep end with no documentation trying to diagnose issues with code that was poorly written and often wrong (hence the issues).
The code always tells people what it does. The comments tell people what you thought it would do, and why it's doing it.
If you think that your code is so good that it doesn't need comments, it's entirely possible that you're just writing unmaintainable garbage that is going to go to hell as soon as somebody else has to maintain it.
I think this because that's what I do at work. Someone wrote this monstrosity of a codebase that is now my problem. I try to simply diagram out the flow of information within this codebase and I end up with a rube-goldberg machine. Data gets passed into highly abstracted classes and functions, disappears into the bowls of the code to some horrible machine somewhere, it spits out a result, sends that result in a message to something else. If you want a new piece of information to make its way from the initial http request all the way through this kafka-esque nightmare, you have to edit something like 5-7 different files, then maybe it'll show up in the right place. But it's not like the genius who wrote this "self-documenting" code actually bothered to write a test suite for it, that would be asking too much.
So get your head out of your ass and write comments. I write them wherever I can, like Theseus weaving a thread through the labrynth, at least maybe I'll be able to find my own way back to places I've been before, or my franticly scrawled directions on the wall will maybe stop some future developer from getting as lost as I've been.
If people write bad code, they write bad comments. Now you have twice as much to read, comprehend, and maintain. I also don’t need a million TODOs, fixmes, and other useless, rough draft additions like “lol, I don’t know why this works.”
Why would a module/function/service called “getuser” get a user? Because the client wants a user. Why does gravity pull?
I think you’re looking for GitHub discussions, work item tickets, or commit messages.
Exactly. And if the section of code, thought simple to understand by reading the code, needs deeper explanation as to the all important why it is there, I'll comment the ticket number that brought about the change.
I'll never forgive my seniors for leaving me, a dude who at that point had little to no javascript experience, with multiple methods using single letter variables with zero documentation
I still use lots of variable names with only a few letters, for intricate algorithmic stuff. That's the meat and potatoes of programming for me - I'm not a fan of gluing together a bunch of existing libraries and doing mostly UI or database work (i.e. webstack)
Either your code is self-documenting and near-unreadable due to serialisedDataUploadConnectionFactoryForPrimaryUswrs like variables, or it is succinct and clean but you probably could explain some things in a comment.
I routinely before writing a method/proc write a block comment with natural language/pseudo code “plan” for what the code should be doing. Also if there’s something more esoteric than simple math and method calls - I usually explicitly explain in the comment that e.g. the invertFlag ^ (logical && conditions || here) works by the magic of XOR
238
u/Immort4lFr0sty May 19 '21
Oh, documentation. I'm working on open source software and I always get the feeling that no one ever wrote even the smallest piss of comments, aside from wet comments like
56
u/IHeartBadCode May 19 '21
That's just arrogance. It typically is language independent.
16
u/RedBlueKoi May 19 '21
I mean, if you hate js...you always can try different language
423
u/moggesmith10 May 19 '21
Windows + Shift + S to take a screenshot
38
u/shaybra shameless May 19 '21
Look sometimes the code is so simple it speaks for itself.
67
u/MurdoMaclachlan public boolean isInt(int i) { return true; } May 19 '21
Image Transcription: Photograph
[The photograph is of a code comment on a computer screen, as follows:]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
32
u/willem640 evil May 19 '21
To be honest, I really believe good code should explain itself, though I also think comments are needed if it's not immediately clear
47
u/ClvrNickname May 19 '21
In my first programming job, I noticed that the senior dev, who had 30 years of experience, never wrote comments. I asked him about this, and he told me that "good code is self documenting".
As it happens he also wrote by far the worst code I've ever seen before or since, so take his advice with a grain of salt.
29
u/[deleted] May 19 '21
suckless devs in a nutshell
10
u/[deleted] May 19 '21
this is actually good practice. the code should be readable enough to not have to be documented (largely)
18
u/DangyDanger May 19 '21
can someone please tell me why should i write docs for a 10 line long method that is pretty easy to understand as is?
1
u/andesz May 19 '21
if the code is clean, comments are unnecessary
also, if you need comments, your code is not clean :D
6
u/TurncoatTony May 19 '21
Normally, I don't leave a comment like this.
The code is enough.
7
u/nucleomancer May 19 '21
No the code shows HOW it is done.
Not WHAT is done, or WHY it is done that way.
(I had a team leader like this... who wrote most of the code... :( )
5
u/Python119 May 19 '21
HAPPY CAKE DAY!!!
2
u/arzen221 May 19 '21
Bruh you don't even tell me what it returns
2
u/Orlando-- May 20 '21
I'll never forgive my seniors for leaving me, a dude who at that point had little to no javascript experience, with multiple methods using single letter variables with zero documentation
2
u/deftware May 20 '21
I still use lots of variable names with only a few letters, for intricate algorithmic stuff. That's the meat and potatoes of programming for me - I'm not a fan of gluing together a bunch of existing libraries and doing mostly UI or database work (i.e. webstack)
2
u/20191124anon Sep 01 '21
Either your code is self-documenting and near-unreadable due to serialisedDataUploadConnectionFactoryForPrimaryUswrs like variables, or it is succinct and clean but you probably could explain some things in a comment.
I routinely before writing a method/proc write a block comment with natural language/pseudo code “plan” for what the code should be doing. Also if there’s something more esoteric than simple math and method calls - I usually explicitly explain in the comment that e.g. the
invertFlag ^ (logical && conditions || here)works by the magic of XOR2
u/bearfuckerneedassist Dec 27 '21
It’s these morons who don’t like comments. Juniors pretending to be wise because they are stuck in a shit place since school and think they know shit.
3
u/Undercoverdog___ May 19 '21
Happy Cake day
3
u/aaroncv3 May 19 '21
This comment is exactly what i think when i write code, only to come back 6 months later and wonder what the hell i was thinking
1
u/jvirish Jun 07 '21
Loser attitude
-1
u/emmittthenervend May 19 '21
Claim: "My code is self-documenting!"
The code: bool getPercentage(int x, int[] y){return x%y[x-1] >0;}
0
u/[deleted] May 19 '21
r/Engrish
-2
u/Dmon1Unlimited May 19 '21
ScumbagDev