Even with a loop you'd need to write down an array or put it into the database. Nothing wrong with that. Also generating it would break it for people who disabled JavaScript in their browser. Or am I missing something here?
I'm one of those rare no JS users, this is exactly how you should do it. It's plain as day which sites do this and which don't. It makes sense for sites like YouTube or Twitch but it bugs the hell out of me when I have to whitelist 10 .js files to read a text-only site.
Also generating it would break it for people who disabled JavaScript in their browser. Or am I missing something here?
Well, you don't have to do the loop in the browser you could also do it on the server side in your template. Templates are also typically cached so it's not like doing that is going to result to a performance hit. Of course, you still need to keep the state names and codes inside an array in your template, putting it in the database though I don't think it makes much sense since it's basically static data.
The problem is that the states should be on the database (it's freakin' data), they should have queried the database and looped through it to generate the html (because no, it was not an isolated incident)
Gotta say I agree. Saying you should put state data in a database and use an api call to get it and a JS loop to generate html is like saying you should use jquery to concat a string. All I see here is bug-free code that took 2 minutes to write.
1- IMO, unless you get thousands of visits (FYI, this website has like 50-100 visits per day) it will make no difference;
2- if you really want to save resources, then keep the data on a file (JSON, XML, whatever the f....), and have method to read it and generate the html
I would still have used a json file though instead of html (the dropdown is being displayed in multiple places). And having the raw data gives the flexibility to generate different html depending on the page.
even if you were generating the list at runtime by reading a file, this is something that is easily cached. database call could be cached too if you wanted to keep it there.
you are going to have to duplicate the list on the server anyway assuming you are validating it. and if you have it there, you can use that same data in the template.
got one of these in my code base. I just copied it from some website though as a placeholder. Other devs ran with it and now this is copied and pasted in 4 different components
56
u/IllegalArgException Oct 02 '18
Even with a loop you'd need to write down an array or put it into the database. Nothing wrong with that. Also generating it would break it for people who disabled JavaScript in their browser. Or am I missing something here?
34
u/AndrewGaspar Oct 03 '18
This is a perfectly acceptable solution.
32
u/dupeddonk Oct 03 '18
Great example of 'non-shitty programming' that a 'shitty programmer' thinks is 'shitty'.
16
u/[deleted] Oct 02 '18
got one of these in my code base. I just copied it from some website though as a placeholder. Other devs ran with it and now this is copied and pasted in 4 different components
https://imgur.com/a/I1Ofibx
2
u/kafoozalum Oct 03 '18
You don't even need to write this anymore, it was probably just copied from a site like this. Tons of sites exist with these pre-made.
Also you mean hand-coded, not hard-coded.
2
u/Carl_Byrd Oct 04 '18
I see nothing wrong with this. This code is already online so just search, copy and paste.
2
u/faitswulff Oct 02 '18
Do you...do you work at my company?
1
u/Bl4ckeagle Oct 03 '18
Wait, is today opposite day?
0
u/Nevik34 Oct 02 '18
Why do you want to hurt me?