As long as start does a start action, who cares what it does in detail though lol.
If it comes to the point where you need comments in your package.json to help people understand what all the scripts are for than you need a better readme OR split things up into a proper make/bash files so you don't end up in && hell
What if I don’t know what react-scripts start mean? I mean this command is intuitive enough. But what if I don’t know English? What if it’s a Linux command but my collaborators are Windows devs?
Imo, most comments aren't helpful, but documentation comments are usually quite nice, especially because most IDEs interpret them to explain the function when you use it.
"start" is the name of the scripts. So it's quite obvious, you don't need to know what command is run from it, could be react-scripts whatever. If they don't speak English, comment won't help them either
If there was ever a time commenting these scripts/commands was necessary, especially if due to complexity, then break it into a shell script and call that. You can comment there all you want, but this is the wrong place to comment it.
Yeah, I think people are too quick on the trigger if this is just meant as quick basic examples.
Edit: dunno why but // feels off. I believe I have seen underscore used and it seemed easier for brain to read as comments.
Remember that tooling and json code highlighting can assist here.
Aaaand, notice test comment actually clarifies it as unit tests. Not sure if CRA test runner can run cypress/testcafe or other type of tests in unison. But not so terrible seeing it here instead of digging into configs to see exactly what tests are ran.
I think that's one of the few reasons why this could possibly make sense.
In my experience, the vast majority of comments in code are at best useless, and at worst actively harmful. They can almost always be replaced by well structured code and meaningful variable/function names.
The few places I've ever seen them actually being valuable is either when there's some unavoidably complex logic involved, which is rarely going to be the case in a JSON file (and would be far better handled by a readme if it really was needed), or to explain something that on the face of it looks dumb or counterintuitive, like your "why is this still on the old version?" example.
I hate that some of my colleagues insist on using JSON as complex configuration files then try to find workarounds like these for adding comments. There are better options like xml, yaml, toml, ini etc.
use json5, it got comments and such things, less bitchy about its syntax too :) Still "json" but without the annoying shit. Yaml is fine too i guess, hate xml for configs.
Json was never intended to be "for humans", it was all about speed and minimizing data. Forcing all these back into it seems like we'd want to use a saddle in a car.
Friends. Let's all take the time to think before writing something. First ,"it literally is tho" grammatically doesn't connect to anything I've said.
Second, the existence of bson doesn't invalidate anything I've said. Json was indented to reduce data while still be usable in http integration. It is human readable, but not for a human to interpret.
And btw, Bson was 9 years AFTER Json, so that they wanted to reduce it further, does not invalidate anything I've said.
I agree with you, perhaps if you'd mentioned the massive bloat that was SOAP/XML it would have been obvious to the other guy how much bandwidth was being saved by using JSON. :)
it gramattically connects to "Json was not meant to be human readable.", the first satement you made. I don't know how you didn't see that.
also, to me at least, json strikes a good balance between simplicity and readability that makes it a good format for configuration files, only real problem being comments (which you can use jsonc/json5 for. PLEASE, if you can help it, don't do what OOP did.)
Sure, it is also designed for easy data interchange thru HTTP, but can't things be designed for more than one thing?
Eh? It's clearly designed to be a portable human readable format, at the expense of speed and file size. If you wanted something fast and small, you'd dump it in a binary format at the very least.
Hmm. You have the ideas, but not in the right places :)
Indeed Json is human readable, as in it is text not binary. But that doesn't mean that the idea was for a human to make sense easily. Complex structures are a nightmare to figure out just be looking at it. But that's ok. Interpretation is a computer task.
And regarding binary. Yeah, you can dump it out then what ? We're talking about integration, HTTP, API, benefits of having it over XML so mobile traffic is reduced. This is the basis of the conversation. Dumping out your binary will not help in this situation.
What you said about binary is true. With a laptop. In a deserted island. Alone.
Or you could copy it to a flash drive, put it in a bottle and hoist it in the sea.
So similar in fact that it is named that. JavaScript Object Notation. Because it is that, with extra steps.
But if you think about it a minute what I might have been referring to, you realize that before it came to pass, the majority of transfer and communication was csv, xml, and other misc models.
When we say fast, and simple ( as you yourself stated ), we are making a distinction to those that were used before. It is never about how a human can understand the data represented.
Because it is simple, it is fast. Fast to serialize and deserialize data. It will always outperform xml, csv, normal text. And takes much less space with no need of closing tags.
Fast, as faster communication, for data is represented in a smaller packet. Fast, as it is more easy to interpret for a computer. And by these it is usually a more efficient data representation model.
You are right, in raw speed, csv is faster. But there is a reason no one wants to implement, god forbid update csv. Json is infinitely more versatile.
and for simple.. that is too broad and relative. Simpler to understand ? CSV Simpler to create data hierarchy ? Json Simpler to implement ? Json Simpler to update ? Json Simpler to make data "safe" ? Json
I honestly like yaml a lot, it's clean, lean, easy to read and write in any editor. The only small thing I don't like is that some people uses .yml and others .yaml, wish they had standardized it right at the beginning.
The problem with yaml is that it's only good for small files really and only if you have a good editor. Indentation based stuff is just asking for trouble imo. Plus it's syntax has some oddities at times, someone below pointed some out so I won't rehash.
But I work with largish files which are around 10-40k lines so XML or JSON usually works best. XML is for sure the easiest to read (human) and has better editors but JSON is easier to work with in code (again imo)
But then again most libraries will skip over comments in JSON files anyway. Who cares if it's invalid as long as the library works!
Plus ultimately it doesn't really matter unless you are doing stuff as incredible scale or very large files as most people just seem to have files under a 100 lines anyway for config which will read almost instantaneously in any format into code with major libs!
It does't mater. My point is that yaml should not be ever used in human-to-machine communication i.e. user editable configuration file. It is ambiguous, fragile and just user hostile. Even MS inf file format is better.
That’s not what I’m reacting to and it does matter. You make it sound like writing a YAML-parser is done by lazy lazy programmers which makes no sense at all.
I can't help. I am simple sysadmin which has to fight with yaml config files, sometimes using vi (not vim) or nano in best case, and hate it every time
Many said “Use a Readme”. Why I prefer inline comments:
It’s natural to read comments above the item being documented
Easily discoverable. Don’t need to find docs in a separate file.
More likely to stay updated Yes, this is a hack. But the benefit > cost.
Also, I don’t recommend commenting every script. Ideally many scripts are simple and well-named, so a comment isn’t necessary. My example is deiberately simple to convey the pattern. I use this approach for complex scripts, when a name alone isn’t sufficient.
Hot take: JSON doesn't support comments because it's not designed to be used as a config file format. Sure, this guy is silly, but so are the thousands of projects that insist on pretending that an interchange format is suitable for config.
In general, bad developers only hang themselves when good developers give them the rope.
It's completely dumb that JSON is used for anything other than data serialization, it's completely unsuitable for config files and such, but that's the world we live in, so this code is great.
YAML is too ambiguous to use it for anything real, JSON5 never got popular, and .config.js files (which 90% of projects end up using) can execute arbitrary code. So we're stuck with JSON.
And it's not just theoretical issue. It's entirely common for yaml saved by one yaml library come out as something different when loaded by another yaml library.
There are cases where some comments make sense, but generally code should speak for itself by variable/function/class naming. If you’re starting out, being a little comment heavy makes sense. If you do complex stuff that can’t be abstracted/seperated it makes sense. But 95% of the time you could do something different and have it more readable without comments allover.
If you have to comment that “start” starts the app, maybe just use start-app instead. If you still want to use “npm start”, just set it to “npm run start-app”.
IMHO hjson is more natural than yml. Yaml has a pretty weird syntax if you ask me. Multiline strings in yaml are unintuitive and the syntax with dashes in situations like these:
a:
- b: c1
d: e1
- d: e2
b: c2
Is just awful. It's just confusing compared to hjson (at least in my opinion)
If you dislike YAML for this, please remember that it is a superset of JSON and you can include any valid JSON literal as a value. If you like JSON in a place, just use it there
Interesting, I didn't know that but now I'm even more confused what the JSON equivalent of the yaml I posted would be. "a" probably a key for an object and the rest?
I’m guessing because of how dogmatic the comment sounded?
In honesty from working with both I see them with different use cases (and this is my POV, not objective): YAML - when you want people modifying the config and don’t have a lot of deep nesting (since YAML depends on indentation it can get messy) JSON - mainly for machine consumption, not to be modified by hand mostly (caveat is I’ve seen it integrated with tools like octopus deploy that make it easier to modify json by hand). Better for larger config files that may have deeper nesting and complex object values.
Just for the very last point I found json was a bit easier to work with when values are json objects and not just primitives vs YAML that I’ve had a weird harder time adding objects as values.
That’s a pretty dodgy way to describe a standard. It makes it sound as if the yaml standard itself contains (and has power over) the json standard, and that the “json-guys” would have to ask the “yaml-guys” for permission before making any change in the json standard.
I mean, technically I could create a new standard called knuflork, and allow yaml syntax inside it, and say “yaml is a subset of knuflork”.
One should be careful with the words subset/superset when discussing standards.
It’s a pretty dodgy way that they describe their standard that way. It makes it sound as if the yaml standard itself contains (and has power over) the json standard, and that the “json-guys” would have to ask the “yaml-guys” for permission before making any change in the json standard.
I mean, technically I could create a new standard called knuflork, and allow yaml syntax inside it, and say “yaml is a subset of knuflork”.
One should be careful with the words subset/superset when discussing standards.
I can’t remember any other format that gave me so much headache and strange problems the first time I was forced to work with it. It’s not intuitive or self explaining at all. Both xml and json are super intuitive in comparison.
Both have a lot of the same pain-points as YAML does. They exist mostly because Yaml sucked, so they created something different that sucks in a different way.
I can Google for „why X sucks“ for all 3 and for all of them get a big list of pain points.
In the end it comes down to personal preference or simply defined standards
Really? I've never really used rust but I love TOML for Go and Python configuration. Unless you need some really complex configs I find it really nice and readable. It's also very easy to parse in the code
Ah. Not a deal breaker for me either. I hated YAML before. I found it ugly. However, after working with GitLab pipelines for a while they grew on me, and I no longer dislike them. But we do have special rules in our team for YAML files. These are related to the above issues. They are enforced by linters and peer review.
Adding string concatenation for every line to pop those quote marks on the ends might not fit in the processor time budget. The easiest solutions aren't always the best.
the standards people can sit on their thrones and decree people are using it wrong all they want, doesn't change the clear need in practice that continues to necessitate these hacks.
What sort of LinkedIn-looking-ass post is this? Yeah, JSON is a garbage formats and should be actively read by humans, but this ain't it (YAML ain't it either).
629
u/ign1fy Dec 27 '22
I would process that faster if the comments weren't there.
254
u/[deleted] Dec 27 '22
Thanks, i hate it
190
u/Romejanic Dec 27 '22
118
u/PooSham Dec 27 '22
I would get it for more complicated commands, but for for simple react-scripts? Pretty self documenting
51
u/crunchy-cookie Dec 27 '22
I don't think I can recover from what I saw. Wow...
32
u/TranquilMarmot Dec 27 '22
Obviously this is not helpful for commands like
start, but we do have something like this:81
u/BogdanPradatu Dec 27 '22
I hate that some of my colleagues insist on using JSON as complex configuration files then try to find workarounds like these for adding comments. There are better options like xml, yaml, toml, ini etc.
13
u/polyworfism Dec 27 '22
Repost bot
https://www.reddit.com/r/badcode/comments/ti802e/this_just_sucks
8
u/buraconaestrada Dec 27 '22
Cory House, First of His Name, Founder of LinkedIn Posts, Software Slayer, Author of Bad Code and Speaker for the House of Proudness. Hear hear!
7
u/NoLookThatWay Dec 27 '22
Does a .jsonc not work in the place of package.json?
5
u/ikeif Dec 28 '22
His follow up:
9
u/[deleted] Dec 27 '22
Thanks. I would never know what the “start” or “test” scripts do without comments
9
u/ICantBelieveItsNotEC Dec 27 '22
Hot take: JSON doesn't support comments because it's not designed to be used as a config file format. Sure, this guy is silly, but so are the thousands of projects that insist on pretending that an interchange format is suitable for config.
In general, bad developers only hang themselves when good developers give them the rope.
3
u/nosrednehnai Dec 28 '22
This is getting loaded into memory lol
3
u/hammersage Dec 28 '22
With ideas this good, I’m not shocked to see he’s the founder of “reactjsconsulting.com”
7
u/taw Dec 27 '22
This is awesome code.
It's completely dumb that JSON is used for anything other than data serialization, it's completely unsuitable for config files and such, but that's the world we live in, so this code is great.
YAML is too ambiguous to use it for anything real, JSON5 never got popular, and
.config.jsfiles (which 90% of projects end up using) can execute arbitrary code. So we're stuck with JSON.4
u/devenitions Dec 27 '22
If shit explains itself, don’t comment it
If shit doesn’t explain itself, wtf are you doing?
2
u/EngineerDirect7992 Dec 27 '22
Cory in the House babyyyy
2
u/[deleted] Dec 27 '22
JSON 5 supports a few new things including real comments 🥳
2
u/Rockytriton Dec 28 '22
how to get paid for doing nothing useful
2
u/ExplodingWario Mar 09 '23
When your pay is determined by the lines you write
9
u/DopeNamePerson Dec 27 '22
…I kinda like it. 🤷♂️
14
u/chadmill3r Dec 27 '22
YAML is the way.
2
u/jimmpony Dec 27 '22
not supporting comments was probably json's biggest mistake
1
u/CodeSmell12 Dec 27 '22
Wow! That's incredible! I must introduce this amazing documentation practice in my team!
1
u/haasilein Dec 27 '22
doesn't make sense here, but in other cases could actually be useful when you have a more complicated workspace config or something like that
1
u/yrevapop Dec 27 '22
A founder did this? Interesting…
1
u/Grtz78 Dec 27 '22
This whole comment section reads like we should finally dump javascript in favor of lisp and be done with object notation 🤣
1
u/[deleted] Dec 27 '22
Isn't there a more advanced version of JSON that supports comments, though?
1
u/zeehyt Dec 27 '22
.jsonc
1
u/scooptyy Dec 27 '22
This isn’t bad code. The examples are bad, but this is becoming common in other codebases.
1
u/FalseWait7 Dec 27 '22
Ah, meaningless comments, my favorite.
This style of comments in
package.jsonis okay, I sometimes use it, when I want to group commands (and in larger projects this come in handy).1
u/millsz416 Dec 27 '22
I think prefer just good script names
1
u/MetaContrarian Dec 27 '22
r/atbge
1
u/ludwig-boltzmann_ Dec 27 '22
One of the teams in my company does this and it drives me nuts
1
u/IxD Dec 28 '22
readme.md folks
1
u/Double_Ad_2824 Dec 28 '22
JSON shouldn't be used for user-editable files imo.
1
u/Da-Blue-Guy Dec 28 '22
hjson crying in the corner
1
u/toastal Dec 28 '22
What sort of LinkedIn-looking-ass post is this? Yeah, JSON is a garbage formats and should be actively read by humans, but this ain't it (YAML ain't it either).
1
u/Cootshk Dec 28 '22
Fun fact: a .jsonc file is a json that supports comments
1
u/HerissonMignion Jan 01 '23
"help-start": "echo "starts the app""
1
u/FalsifyTheTruth Jan 07 '23
just include a fucking readme
1
u/diaperslop Jan 08 '23
Solutionism
1
u/RicePsychological512 Dec 27 '22
I thought this was a joke, but it isn't.
It would be nice to see a case where he felt like he needed to comment a script. start is a weird one.
Corey House usually makes more sense than this, so it feels likely I am being dismissive of a use case I just haven't seen.
0
u/Cherry-PEZ Dec 27 '22
This has to be rage bait
0
u/[deleted] Dec 27 '22
{
"val1": 1,
"val2": 3,
"comment": "I am hungry"
}
0
u/andoriyu Dec 27 '22
UCL or fuck off. Yaml is bad, Json is bad, toml only good for very lightly nested structures (i.e. cargo.toml the rest [[can.fuck.off]]).
-2
u/Luceriss Dec 27 '22
I hate JavaScript so much
0
u/[deleted] Dec 27 '22
[deleted] — view deleted comment
0
u/[deleted] Dec 27 '22
[deleted] — view deleted comment