The real crime are the leading blank lines in the html file. Internet Explorer would render that in quirks mode if doctype is not in the very first line.
I don’t know why you’ve been down voted but here take my upvote.
I’m not a js expert but as far as I know it’s recommended to create a const variable that can be used as an enum for better maintainability. Correct me if I’m wrong.
Methods made with the 'function' keyword have their own this context which is different from the one of the object holding them.
Arrow functions don't. That's why they are better in this case, because 'this' would refer to the object not the method even when called from within the arrow function. And that's nearly everytime what you want
I've seen a system that check enum values through separate API endpoints. The database had a column called role with values Student, Teacher and Admin, but the frontend has access to it through /api/Student/IsTeacher and /api/Student/IsStudent.
I see, my school's site uses react I think, so the source code is just a jumbled mess. Honestly, I rarely find sites that have their actual code viewable, they're usually scrambled.
It looks scrambled because it's the output of webpack from bundling/optimizing together a bunch of node modules and, of course, the actual code itself. The scrambled code is the result of trying to make the size of the website as small as possible. If you view a website that doesn't have scrambled code, chances they probably made something from jQuery, vanilla JS, etc.
Not sure why this is bad code other than the duplicate entry. From the looks of it this is used to declare variables in a view. This is a lot cleaner than writing the complete conditional in the view itself.
Why people in this sub think that writing conditional expressions with chained logical operators is bad code?
That second image is super simple to read. It’s just trying to determine if a bunch of conditions are met before determing if the step 1 is completed.
Is there a better way to do that? Possibly. But that’s far from bad code.
We don’t know if this is client or server code, or if the developer was able to modify the data model. I refuse to judge this piece of code without knowing that.
111
u/spiderjail Sep 21 '21
Yo this code is beautiful compared to some of the shit I have to work with every day
30
u/bistr-o-math Sep 21 '21
The real crime are the leading blank lines in the html file. Internet Explorer would render that in quirks mode if doctype is not in the very first line.
Wait. Is Internet Explorer still a thing?
24
u/menjav Sep 21 '21
What’s wrong?
23
u/[deleted] Sep 21 '21
There is gonna be a problem with the this context But aside from that not so bad. Use strict equality, and arrow function and that's good to go
6
u/Svizel_pritula Sep 21 '21
I've seen a system that check enum values through separate API endpoints. The database had a column called
rolewith values Student, Teacher and Admin, but the frontend has access to it through/api/Student/IsTeacherand/api/Student/IsStudent.5
u/jzaprint Sep 21 '21
How does someone get access to the schools codebase?
4
u/coecks Sep 21 '21
Not sure why this is bad code other than the duplicate entry. From the looks of it this is used to declare variables in a view. This is a lot cleaner than writing the complete conditional in the view itself.
4
u/[deleted] Sep 21 '21
Why not use a key value pair to create a mapping ....
2
u/periidote Sep 21 '21
did this bitch title their page “404 not found”? mad lad right there
3
u/whoisjuan Sep 21 '21 edited Sep 21 '21
Why people in this sub think that writing conditional expressions with chained logical operators is bad code?
That second image is super simple to read. It’s just trying to determine if a bunch of conditions are met before determing if the step 1 is completed.
Is there a better way to do that? Possibly. But that’s far from bad code.
We don’t know if this is client or server code, or if the developer was able to modify the data model. I refuse to judge this piece of code without knowing that.
1
u/yuelu0122 Sep 22 '21
It’s readable at least