Hacker News new | past | comments | ask | show | jobs | submit login
Tiny Little Elevator Simulator (Qt) (aminbandali.com)
7 points by aminbandali on Aug 18, 2013 | hide | past | favorite | 6 comments



Just looking at elevator.cpp briefly, it seems like some comments are unnecessary, e.g., stating that the constructor is the constructor. Also, I was confused by the switch statement that took a boolean and had a case for true and false. Why didn't you use an if statement?


>Also, I was confused by the switch statement that took a boolean and had a case for true and false. Why didn't you use an if statement?

You know, it never occurred to me to do that, but I think there may be times when that would be a clearer idiom than an if statement (as long as you put "default:" immediately after "case true:"). I always feel like the order of clauses in an if-else gives a sense of privilege to whichever case is handled first, but there's less of that sense with a switch statement.

In particular, I think it might be a good alternative to conditionals on non-boolean arguments. For example, instead of:

    if(countDown) {
        countDown--;
    } else {
        blastOff();
    }
You could use:

    switch (countDown) {
        case 0:
            blastOff();
            break;
        default:
            countDown--;
    }


Thanks for your comment. Yes I know, and I'm sorry for that but I pretty much had to explain everything in comments because it was a high school project and our teacher wasn't really familiar with Qt framework. And about the switch statement, you're right, I should have used an if in that case. The code looks kind of funny but at least it's good to see how much I've progressed during these months. I'll publish some of my recent projects soon!


There's something about elevators and early-stage computer science students. I remember that writing a lift scheduling algorithm was a really popular project at my school. I think it's because in the arrogance of youth we think that the only reason people have to wait for elevators is because Otis hasn't embraced the computer age. With just a little application of programming skill everything could be so much better. Never mind that it's actually really hard...

This isn't a dig at the poster; it just sparked some memories.


We had to make this as a "practicum" in our computer science class.

This is what I made in about 5 hours (java)

https://gist.github.com/brambram/6261967

(it was made in 2 sessions, in the 2nd session we had to expand the elevator code so it supported 2D movement)


Wow! This is pretty cool! A lot better than mine :p congrats and thanks for sharing!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: