3 ms·
Honest question. What is wrong with something like that? I could see it justified by saving the overhead of a complex Date class.
by AdamTReineke 15y ago
Honest question. What is wrong with something like that? I could see it justified by saving the overhead of a complex Date class.
- nagrom 15y agoI had the same question. I had these thoughts: It looks like python, so the semi-colons are unnecessary. If you want to rid yourself of datetime for whatever reason, implement it as a list, returning name_of_day[x], so that you can start the week on a Sunday(=0) easily if you want to. Beyond that, I'm stuck too :-(
- serge2k 15y agoIf you are going this route why not use a switch? Or just an array.
- MrMan 15y agopython have no switch
- bluekeybox 15y agoTwo words: mapping structures.
- MostAwesomeDude 15y agoPython ships with a standard datetime class which is powerful enough to represent time, and there is a ubiquitous module, dateutil, which extends it to do nearly anything people need to do with dates regularly. Additionally, one would normally use an array of names and index it: days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] that_day_you_wanted = days[x]
- metachris 15y agoIt's just inelegant. A better approach would be an array where you return the content at the index.
- avstraliitski 15y ago1. Internationali[sz]ation. Never hardcode strings in code that is part of a real system that will be maintained and has any chance at all of moving forward. In the US, Spanish support is the obvious one. Globally, good programmers should get in the habit of always coding in a way that adequately supports Chinese, Arabic (right to left), etc. If you don't know how to do this, figure it out now and charge extra at your next gig: it's in demand, trust me. 2. Cherry-picked example factor. Hardcoding date strings is doubly bad, as they are usually provided by any modern system. Good libraries will also provide abbreviations (Monday = Mon = M), different calendar systems, etc. this problem is nearly as old as computing and elegantly solved many times over. Anyone who does not realise this is simply not experienced. Any team that allows such code past reviews and/or group reading is incompetent.