Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So true. Finance attracts the most incompetent egomaniacs possible. I love getting lectures about how to design software from someone who has written:

    if x == 0:
        return "Monday";
    elif x == 1:
        return "Tuesday";
    ...
This should be a criminal offense.


Honest question. What is wrong with something like that? I could see it justified by saving the overhead of a complex Date class.


It's just inelegant. A better approach would be an array where you return the content at the index.


If you are going this route why not use a switch?

Or just an array.


python have no switch


I 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 :-(


Two words: mapping structures.


Python 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]


I have a better one. Project manager replaced enums with strings and instead of the switch statement he put a long list of if-s (without the else-s, too), and a lot of obfuscated crap between the braces.. Guess who had to sort out that mess? Also, the motivation for that horror was related to how those string parameters were visible in intellisense (because they were made static members in a class). Don't even ask.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: