You know you're in for a bad day of programming when....

Discussion in 'General Discussion' started by Simon F, Sep 28, 2009.

  1. Gubbi

    Veteran

    Joined:
    Feb 8, 2002
    Messages:
    3,661
    Likes Received:
    1,114
    I basically started out with a machine code monitor as well. In fact the first one I used didn't even have support for mnemonics, you just had a hexdump of upcodes. In fairly short order (8-9 months) I got a monitor with mnemonic support, then progressed to Commodores slow as molassees two pass file based assembler and finally on to Turbo Assembler which had everything in RAM and was lightning fast.

    cheers
     
  2. 2senile

    Regular

    Joined:
    Feb 19, 2003
    Messages:
    317
    Likes Received:
    0
    Location:
    Fantasy Land
    ..... you realise that the last thing you Programmed for was the Spectrum! :runaway:
     
  3. Sc4freak

    Newcomer

    Joined:
    Dec 28, 2004
    Messages:
    233
    Likes Received:
    2
    Location:
    Melbourne, Australia
    With regards to GOTO, I think it's acceptable in C but not C++. In C, it's used frequently for handling errors. There's really no other elegant solution for handling cleanup at the end of a function in the event of an error.

    In C++, you should be using RAII which is a far superior solution to manual cleanup. Having objects clean up after themselves not only eliminates the need for GOTO, it also aids in staying exception-safe.

    For things like nested loops, I prefer sentinel booleans to signal exit. This works just fine for doubly- and triply-nested loops. If your loops are so deep that sentinel variables become unwieldy and you think you need a GOTO, you probably need to refactor your code.
     
  4. Simon F

    Simon F Tea maker
    Moderator Veteran

    Joined:
    Feb 8, 2002
    Messages:
    4,563
    Likes Received:
    171
    Location:
    In the Island of Sodor, where the steam trains lie
    "Sentinel Boolean"? I've not heard the term before. Care to elaborate because a Google search didn't return anything that was immediately enlightening.
     
  5. Freak'n Big Panda

    Regular

    Joined:
    Sep 28, 2002
    Messages:
    898
    Likes Received:
    4
    Location:
    Waterloo Ontario
    Sometimes programming really drives me insane, I wasted about 4 hours today trying to figure out how to use a function in VBA. absolutely retarded. After I figured out that it had to be called via a sub routine I coded everything i needed to code in about 15 minutes... arg.
     
  6. Rodéric

    Rodéric a.k.a. Ingenu
    Moderator Veteran

    Joined:
    Feb 6, 2002
    Messages:
    4,080
    Likes Received:
    997
    Location:
    Planet Earth.
    I assume something like
    Code:
    bool bContinue = true;
    for ( int i = 0; i < 100 && bContinue; ++i )
    {
       if ( ... )
       {
          ...
          bContinue = false;
       }
       else
       {
          ...
       }
    }
    
     
  7. Sc4freak

    Newcomer

    Joined:
    Dec 28, 2004
    Messages:
    233
    Likes Received:
    2
    Location:
    Melbourne, Australia
    That's the idea. Perhaps it would have been clearer if I had said "using a boolean variable as a sentinel".

    Code:
    bool timeToExit = false;
    for(int i = 0; i < 10; ++i)
    {
        for(int j = 0; j < 10; ++j)
        {
            if(...)
            {
                timeToExit = true;
                break;
            }
        }
        if(timeToExit)
            break;
    }
    
     
  8. pcchen

    pcchen Moderator
    Moderator Veteran Subscriber

    Joined:
    Feb 6, 2002
    Messages:
    3,018
    Likes Received:
    582
    Location:
    Taiwan
    This is quite common in C/C++, but I think it's not a very good solution, because if you modify the program to add another layer of loop, you'll have to remember to add another sentinel. This can be problematic when the loop is large and there're more than just a few people maintaining the same code.

    I think it's still better to have a Java/C# style of "lable break" to be able to break from deep loops.
     
  9. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    17,884
    Likes Received:
    5,334
    Upon starting a programming course
    on the first day we had an induction, were some woman wen over the course details rules ect
    "We dont tolerate sexism racism ect"

    /Me puts hand up
    "Does that include the french"
    cue laughter from fellow students.

    she looks at me rather awkwardly "yes it does" she says sharply.
    "and now a quick word from the faculty head Mr Corbière"

    oops....
     
  10. Fred

    Newcomer

    Joined:
    Feb 18, 2002
    Messages:
    210
    Likes Received:
    15
    I wish people still programmed in Pascal. Really elegant code to learn with, and not the horrendous hack that is C.
     
  11. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    17,884
    Likes Received:
    5,334
    I loved pascal, started on ms quick pascal 1.0
    the great thing about ms qp was the compiler error msg's were stored as a plain text file and you know how obtuse compiler error msg's can be. Thus began project plain english, where i changed all the msg's into something more understandable
    eg: "unexpected end of line" was changed into " you missed out the ' you wanker"
    ect, ect ect
    it became a cult hit at my college.
    and that is the story of my greatest contribution to programming.
     
  12. flynn

    Regular

    Joined:
    Jan 8, 2009
    Messages:
    400
    Likes Received:
    0
    I love programming in C and assembly language but I fully agree: a person's first exposure to programming should never be C. I learned Pascal in high school and Modula-2 at university. By that time I had already spent quite a while programming the Amiga in mc68k assembler so it took me a while getting used to Modula-2. But it was well worth it.

    These days I would probably recommend starting with Python. Very easy to get started with yet very powerful if you decide to dig down the rabbit hole. I always use it for rapid prototyping.
     
  13. Mintmaster

    Veteran

    Joined:
    Mar 31, 2002
    Messages:
    3,897
    Likes Received:
    87
    I always thought that they're quite similar, as I found the transition from Pascal to C very easy.

    I do agree with you, though. Although I didn't have an issue with it, clearly distinguishing assignment from equality with := is good for beginners to programming. I remember helping someone out with BASIC and he had some confusion with that, thinking "a = b + c" is the same as "b + c = a", and having some fundamental misconceptions how how programs work.

    And mmendez, you can use inline assembly in some Pascal compilers, too. :cool:
     
  14. pcchen

    pcchen Moderator
    Moderator Veteran Subscriber

    Joined:
    Feb 6, 2002
    Messages:
    3,018
    Likes Received:
    582
    Location:
    Taiwan
    In the original BASIC, assignment has to prefix with a "LET" IIRC. i.e. LET a = b + c. But when I was using my first BASIC it's already not the case anymore :p
     
  15. rpg.314

    Veteran

    Joined:
    Jul 21, 2008
    Messages:
    4,298
    Likes Received:
    0
    Location:
    /
    I started my programming with C++. The language *almost everyone* in this country has first exposure to. And after so many years, I sorta like C. Clean, simple, minimal, insanely powerful (only if you know what you are doing) ....
     
    #55 rpg.314, Oct 13, 2009
    Last edited by a moderator: Oct 13, 2009
  16. Simon F

    Simon F Tea maker
    Moderator Veteran

    Joined:
    Feb 8, 2002
    Messages:
    4,563
    Likes Received:
    171
    Location:
    In the Island of Sodor, where the steam trains lie
    At least is was better than COBOL's RSI-inducing "multiply A by B giving C" :)
     
  17. Gubbi

    Veteran

    Joined:
    Feb 8, 2002
    Messages:
    3,661
    Likes Received:
    1,114
    I always liked Beta's (a Simula derivative) syntax for assignment:

    a*10+b -> c

    Chronological order is maintained reading from left to right. It is also the way a hardware engineer would think about operations.

    Cheers
     
  18. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    17,884
    Likes Received:
    5,334
    Or pigin english as we used to call it...
     
Loading...

Share This Page

  • About Us

    Beyond3D has been around for over a decade and prides itself on being the best place on the web for in-depth, technically-driven discussion and analysis of 3D graphics hardware. If you love pixels and transistors, you've come to the right place!

    Beyond3D is proudly published by GPU Tools Ltd.
Loading...