As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

[Programming] Thread: Fixed last bug in 5 month thread

1192022242599

Posts

  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited April 2015
    wat? that... who... i don't even understaaaaaand!

    iTunesIsEvil on
    htmecco the dolphinbowenNaphtali
  • LD50LD50 Registered User regular
    Goddamn it

    Better variable names man

    What the heck is "position" referring to?

    There are at least 4 physical positions in this system, not including any of the virtual positions.

    The variable name is so vague as to be meaningless, and worst case misleading. D:

    Edit:

    Protip for Programmers

    What is obvious right now in the heat of the moment will not be obvious in a few week's time when you/someone else revisits the code.

    Either comment the code, or make it so that there's no ambiguity in your variable/function names.

    Personal Opinion: A difference between a good developer and a crappy code monkey is the bolded - you write code not just to solve the immediate problem, but also think about maintenance and how it will interact with other code/people.

    So name all your variables after things with deep emotional connotations. Friends, family, religious figures, characters from popular fiction.
    Snape.kill(Dumbledore)
    

    ecco the dolphincrimsoncoyotebowenironsizidePolaritieVegemyte
  • MadpoetMadpoet Registered User regular
    The temporary admin page I put in last night has a call that reads:
    Yolo(swag)
    
    so that I know to nuke it from orbit the next time I see it.

    ecco the dolphincrimsoncoyote
  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    edited April 2015
    Ecco's Daily WTF
    const bool output_to_network = true;
    const bool not_output_to_network = false;
    

    I kid you guys not.

    This is what I just found. This also has many associated multiple levels of fail - ignoring the obvious WTFs there:

    1.) This was inside a header file for an unrelated class. What the header file for a class is doing controlling network output is a mystery.
    2.) A "Find in Files" indicates that nothing else references this. Why is this even here in the first place?*
    3.) Placed without decoration in a namespace shared between multiple classes. Whhhhy? Why would you hurt another developer and stop them using those names like this?

    Thankfully, due to #2, I can just nuke it from orbit.

    *sigh*

    This day is going to be so good when it's over.

    * Yes, it was probably used at one stage. And now it's just leftovers. Should have been removed when the functions that were using it were removed.

    EDIT #2:

    Hey, guess what I just found by going down a few lines:
    const double divide_zero = 1e-4;
    ...
    const double DIVIDE_ZERO = 0.0000001;
    

    Well done whoever wrote this. Well done.
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    The Anonymous on
    LD50
  • ecco the dolphinecco the dolphin Registered User regular
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.

    Penny Arcade Developers at PADev.net.
    bowen
  • crimsoncoyotecrimsoncoyote Registered User regular
    LD50 wrote: »
    Goddamn it

    Better variable names man

    What the heck is "position" referring to?

    There are at least 4 physical positions in this system, not including any of the virtual positions.

    The variable name is so vague as to be meaningless, and worst case misleading. D:

    Edit:

    Protip for Programmers

    What is obvious right now in the heat of the moment will not be obvious in a few week's time when you/someone else revisits the code.

    Either comment the code, or make it so that there's no ambiguity in your variable/function names.

    Personal Opinion: A difference between a good developer and a crappy code monkey is the bolded - you write code not just to solve the immediate problem, but also think about maintenance and how it will interact with other code/people.

    So name all your variables after things with deep emotional connotations. Friends, family, religious figures, characters from popular fiction.
    Snape.kill(Dumbledore)
    
    I think we're more likely to see
    Bowen.stab(everyone)
    

    ecco the dolphinDelmainbowenironsizidePolaritieadmanbVegemyte
  • htmhtm Registered User regular
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.

    Wait. One single person is responsible for the mess you've been posting? It's not just the accumulated stupidity of a legacy code base through the ages?

    If that's true, then I think what you mean is that your peer's attempt at programming failed spectacularly.

    ecco the dolphinironsizide
  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    edited April 2015
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.
    Did they apologise?

    The Anonymous on
    htm
  • ecco the dolphinecco the dolphin Registered User regular
    edited April 2015
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.
    Did they apologise?

    No, because they think that they're a special little embedded developer snowflake who can break the rules because they know better.

    =/

    Edit:

    I am currently burning this particular class to the ground and redoing it from the ground up due to several failures and making the code practically unmaintainable/extensible.

    1.) It's very much not thread-safe, despite me mentioning this to him over the last few months. According to the comments, he thinks that a big circular buffer will save him. Based on the reported bugs, I beg to differ.
    2.) There's copious amounts of copy/paste/change one line.
    3.) There's use of static variables in member functions (not to be confused with static member variables). This hits the previous two points.
    4.) Exciting and amazing use of old school C style (not really even modern C style) string handling calls. I swear I think some of these C functions are obsolete...? Potential buffer overflows ahoy, either way.
    5.) Just general crap coding (mismatched indents, the ummm... "anti-separation of concerns" design pattern)

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • htmhtm Registered User regular
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.
    Did they apologise?

    No, because they think that they're a special little embedded developer snowflake who can break the rules because they know better.

    =/

    Imposter, IMO.

    A real embedded developer wouldn't touch C++. If they can't crank out 68K asm or Forth, you need to tell them to GTFO.

    ecco the dolphin
  • InfidelInfidel Heretic Registered User regular
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.

    To be fair, this shit is embarrassing things you'd expect from a course group let-down.

    I mean, I hear, I never had a bad group myself. But I definitely have not seen anyone paid for the work you're describing.

    OrokosPA.png
    ecco the dolphinbowenmightyjongyo
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    LD50 wrote: »
    Goddamn it

    Better variable names man

    What the heck is "position" referring to?

    There are at least 4 physical positions in this system, not including any of the virtual positions.

    The variable name is so vague as to be meaningless, and worst case misleading. D:

    Edit:

    Protip for Programmers

    What is obvious right now in the heat of the moment will not be obvious in a few week's time when you/someone else revisits the code.

    Either comment the code, or make it so that there's no ambiguity in your variable/function names.

    Personal Opinion: A difference between a good developer and a crappy code monkey is the bolded - you write code not just to solve the immediate problem, but also think about maintenance and how it will interact with other code/people.

    So name all your variables after things with deep emotional connotations. Friends, family, religious figures, characters from popular fiction.
    Snape.kill(Dumbledore)
    

    I see that you too follow The Guide
    Choose variable names with irrelevant emotional connotation. e.g.:
    marypoppins = (superman + starship) / god;
    

    This confuses the reader because they have difficulty disassociating the emotional connotations of the words from the logic they're trying to think about.

    ecco the dolphinThe AnonymouscrimsoncoyoteVegemyte
  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.
    Did they apologise?

    No, because they think that they're a special little embedded developer snowflake who can break the rules because they know better.

    =/

    Edit:

    I am currently burning this particular class to the ground and redoing it from the ground up due to several failures and making the code practically unmaintainable/extensible.

    1.) It's very much not thread-safe, despite me mentioning this to him over the last few months. According to the comments, he thinks that a big circular buffer will save him. Based on the reported bugs, I beg to differ.
    2.) There's copious amounts of copy/paste/change one line.
    3.) There's use of static variables in member functions (not to be confused with static member variables). This hits the previous two points.
    4.) Exciting and amazing use of old school C style (not really even modern C style) string handling calls. I swear I think some of these C functions are obsolete...? Potential buffer overflows ahoy, either way.
    5.) Just general crap coding (mismatched indents, the ummm... "anti-separation of concerns" design pattern)
    @bowen will likely be here soon to give you some sage advice.

    Do not listen to a single word of it.

    ecco the dolphinPolaritieMvrck
  • LD50LD50 Registered User regular
    I do, and it's something I recommend all programmers read at some point, and take to heart. Not even in a tongue in cheek way either. It does an excellent job of not only showing what not to do, but it shows why doing things like that is so destructive.

    ecco the dolphinironsizide
  • MadpoetMadpoet Registered User regular
    I don't know if I've gushed about DbContext.Database.Log yet, but in case not...
    I have a web API like thing that does stuff then spits out JSON. When it dies, it can be a little cryptic. So I put this together so I could get debug info out without throwing exceptions or wading through guts:
            public static Result SaveDB(DbContext db, bool logSuccess=false)
            {
                var log = new List<string>();
                var old = db.Database.Log;
                db.Database.Log = log.Add;
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return Fail( Message: ex.Message,  Data: log);
                }
                finally
                {
                    db.Database.Log = old;
                }
                return Win(Data: logSuccess ? log : null);
            }
    

    I was going to delete this instead of posting, but I just accidentally deleted the file I'd created it in instead of committing it and came back here to retrieve it from draft, so I figure I shouldn't fight divine providence.

  • bowenbowen How you doin'? Registered User regular
    How have you managed to not burn it all to the ground for this long? Five minutes of this shit would've done it for me, no exaggeration.

    To my shame, I have actually blown up at the dev in question. =/

    My attempts at peer programming failed spectacularly because I couldn't handle it.
    Did they apologise?

    No, because they think that they're a special little embedded developer snowflake who can break the rules because they know better.

    =/

    Edit:

    I am currently burning this particular class to the ground and redoing it from the ground up due to several failures and making the code practically unmaintainable/extensible.

    1.) It's very much not thread-safe, despite me mentioning this to him over the last few months. According to the comments, he thinks that a big circular buffer will save him. Based on the reported bugs, I beg to differ.
    2.) There's copious amounts of copy/paste/change one line.
    3.) There's use of static variables in member functions (not to be confused with static member variables). This hits the previous two points.
    4.) Exciting and amazing use of old school C style (not really even modern C style) string handling calls. I swear I think some of these C functions are obsolete...? Potential buffer overflows ahoy, either way.
    5.) Just general crap coding (mismatched indents, the ummm... "anti-separation of concerns" design pattern)
    @bowen will likely be here soon to give you some sage advice.

    Do not listen to a single word of it.

    Take a shit, place it in your hand, smear it on his face.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen How you doin'? Registered User regular
    Wouldn't using a mutex make your class mostly thread safe? Why would you use a large place in memory and circular buffers for that?

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
    ecco the dolphin
  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    Complete newbie question

    Is there any reasonably good resources to learn Java online? Or is a textbook going to be the best bet? I'm in Australia, so a lot of seemingly fantastic American textbooks will be a pain to get over here, and I was hoping to find something online, but so far everything I've turned up with Google has been not so useful.

    Most of them have seemed like great Java tutorials for an experienced programmer of other languages, but fallen flat for an actual programming novice, which is what I am.

  • bowenbowen How you doin'? Registered User regular
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    edited April 2015
    A quick perusal of that one shows that it seems to have the same problem the others did - namely, it doesn't explain a lot of what it is doing.

    For example, the first program it has you write after Hello World is an example to demonstrate enums

    The concept of enums seems simple enough, it's a restricted variable

    but here is the code they use.
    Example:
    class FreshJuice {
    
       enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }
       FreshJuiceSize size;
    }
    
    public class FreshJuiceTest {
    
       public static void main(String args[]){
          FreshJuice juice = new FreshJuice();
          juice.size = FreshJuice. FreshJuiceSize.MEDIUM ;
          System.out.println("Size: " + juice.size);
       }
    }
    

    zero explanation for any of that. I understand that enum FreshJuiceSize{ SMALL, MEDIUM, LARGE } declares the variable's restrictions
    and I understand the println line

    but I don't really understand what they are doing with "FreshJuiceSize size;" and

    FreshJuice juice = new FreshJuice();
    juice.size = FreshJuice. FreshJuiceSize.MEDIUM ;

    and they don't explain any of it. I'm assuming that the line referring to medium is where they declare what the variable actually is for the purpose of the printout

    Dhalphir on
  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    edited April 2015
    And I know that someone in here can probably explain what they mean by the above code, but that's not the point - if the tutorial itself doesn't explain things to a complete beginner as it goes along, it's not much of a tutorial, as I'd have to constantly keep stopping and doing separate research to determine what is what

    Dhalphir on
  • urahonkyurahonky Registered User regular
    @Dhalphir I find books to teach you a programming language to fall very short. Look on Youtube for videos that people have posted.

  • bowenbowen How you doin'? Registered User regular
    edited April 2015
    Hmm good points, I think a beginner book might be good.

    Deitel & Deitel make some good "beginner" books. You'll get a lot of people that harp on them, but I found them pretty decent.

    http://www.amazon.com/exec/obidos/ASIN/0131426486/deitelassociatin

    Then follow it up with

    http://www.amazon.com/exec/obidos/ASIN/0133807800/deitelassociatin

    You might be able to start with that bottom one, though. Check them out.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • urahonkyurahonky Registered User regular
    Dhalphir wrote: »
    And I know that someone in here can probably explain what they mean by the above code, but that's not the point - if the tutorial itself doesn't explain things to a complete beginner as it goes along, it's not much of a tutorial, as I'd have to constantly keep stopping and doing separate research to determine what is what

    This is going to happen regardless and will happen with about 90% of all programming tutorials unfortunately. There will be a lot of "how in the fuck...?" moments when learning your first language.

    SageinaRageironsizide
  • urahonkyurahonky Registered User regular
    Also programming books from 2003 may not be too relevant for Java 1.7+

  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    I generally struggle to learn via videos. I read much much faster than I can listen, and I get incredibly impatient with videos. But I will have a look and see what I can find :) Thanks

    Sceptre
  • DelmainDelmain Registered User regular
    edited April 2015
    E: woops, I misread it.

    Yeah, it's a downside of object oriented programming. There's a lot of structure around how things work that you could spend a long time figuring out.

    Instead, most tutorials are going to start with a lot of handwaving. They'll go back and explain why things are the way they are later.
    public static void main(String args[]){
    

    is my favorite instance of this.

    When I learned Java, my teacher just said to accept that this is the code that means "start my program here", but then in a few months, we knew everything about that line and why it made the program start.

    Delmain on
    urahonkycrimsoncoyoteironsizide
  • KambingKambing Registered User regular
    Dhalphir wrote: »
    Complete newbie question

    Is there any reasonably good resources to learn Java online? Or is a textbook going to be the best bet? I'm in Australia, so a lot of seemingly fantastic American textbooks will be a pain to get over here, and I was hoping to find something online, but so far everything I've turned up with Google has been not so useful.

    Most of them have seemed like great Java tutorials for an experienced programmer of other languages, but fallen flat for an actual programming novice, which is what I am.

    I don't think there's a good resource to learn how to program in Java online (as opposed to learning the Java programming language itself). My recommendation is this book:

    http://www.buildingjavaprograms.com/

    Which is what I have used in the classroom before—it's simply excellent, and it is focused on learning how to program rather than learn Java minutiae.

    @Dhalphir If you can't find a copy easy (you can buy an ebook version), PM me, and I'll see what I can do...

    @TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    edited April 2015
    Sorry, I should have clarified that I didn't want to learn how to "program online".

    I want to learn how to program...online, ie, put a tutorial of something up on a secondary monitor while I code in a primary monitor. That ebook looks pretty good.

    I'll add you as a friend on Steam Kambing, I can't believe I haven't already.

    Dhalphir on
  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    The ebook version of that doesn't appear to be accessible for Australian users.

  • urahonkyurahonky Registered User regular
    Also keep in mind @Dhalphir I'm not saying anything here as a knock against you but I've been doing this for around 8+ years and I STILL have to google "how in the fuck does this work" and come into this thread and ask dumb questions all the time. I think explaining everything line by line on what it does will overwhelm you.

    Take things as they come and if you have no idea what it does then either: open a new tab and google "java enum tutorial", or assume what's going on is "automagical" and revisit at a later time.

    Delmainecco the dolphin
  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    edited April 2015
    so basically, if they're explaining enums or anything else and show an example program which includes lots of stuff that isn't explained, don't be afraid to copy the code word for word from their lesson and trust that they'll explain it eventually?

    Dhalphir on
    urahonkyDelmain
  • bowenbowen How you doin'? Registered User regular
    urahonky wrote: »
    Also programming books from 2003 may not be too relevant for Java 1.7+

    The core of Java 1.7 is almost no different than Java 1.4.

    Not appreciably, anyways, the language differences might be enjoyed by someone like you and me, not by someone learning.

    Would you be upset if I recommended a C++ book written by Stroustrup that talks about c++98 over c++11 ?

    But an int32 is an int32 and an if/else is an if/else!

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen How you doin'? Registered User regular
    Dhalphir wrote: »
    so basically, if they're explaining enums or anything else and show an example program which includes lots of stuff that isn't explained, don't be afraid to copy the code word for word from their lesson and trust that they'll explain it eventually?

    They should be explaining what enums are, though, if it's being brought up in a code example. Even if it's "we'll talk about this more in chapter 5".

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • urahonkyurahonky Registered User regular
    Dhalphir wrote: »
    so basically, if they're explaining enums or anything else and show an example program which includes lots of stuff that isn't explained, don't be afraid to copy the code word for word from their lesson and trust that they'll explain it eventually?

    Or crack open an IDE and type it in yourself and see what happens and if it works. Then step through the code. I can't really say what that tutorial is doing though. If they don't eventually explain the structure of an enum on an enum tutorial then I'd say it's a bad tutorial. :)

  • urahonkyurahonky Registered User regular
    bowen wrote: »
    urahonky wrote: »
    Also programming books from 2003 may not be too relevant for Java 1.7+

    The core of Java 1.7 is almost no different than Java 1.4.

    Not appreciably, anyways, the language differences might be enjoyed by someone like you and me, not by someone learning.

    Would you be upset if I recommended a C++ book written by Stroustrup that talks about c++98 over c++11 ?

    But an int32 is an int32 and an if/else is an if/else!

    Only if things being taught are deprecated in the future releases and I have the later versions installed on my machine.

  • SageinaRageSageinaRage Registered User regular
    Dhalphir wrote: »
    so basically, if they're explaining enums or anything else and show an example program which includes lots of stuff that isn't explained, don't be afraid to copy the code word for word from their lesson and trust that they'll explain it eventually?

    Yes, particularly for a total beginner. Lots of languages, and java especially, have a certain hump you have to get over in order to understand enough to make a workable program. Most tutorial writers will give you workable code chunks without expecting you to understand everything in them. Most people prefer to have an actual working example rather than go step by step through every single building block before you can actually run code.
    bowen wrote: »
    urahonky wrote: »
    Also programming books from 2003 may not be too relevant for Java 1.7+

    The core of Java 1.7 is almost no different than Java 1.4.

    Not appreciably, anyways, the language differences might be enjoyed by someone like you and me, not by someone learning.

    Would you be upset if I recommended a C++ book written by Stroustrup that talks about c++98 over c++11 ?

    But an int32 is an int32 and an if/else is an if/else!

    The only thing I can think of that might be a big deal would be generics. That was a pretty big change.

    sig.gif
    bowenDelmainIncindium
  • bowenbowen How you doin'? Registered User regular
    urahonky wrote: »
    bowen wrote: »
    urahonky wrote: »
    Also programming books from 2003 may not be too relevant for Java 1.7+

    The core of Java 1.7 is almost no different than Java 1.4.

    Not appreciably, anyways, the language differences might be enjoyed by someone like you and me, not by someone learning.

    Would you be upset if I recommended a C++ book written by Stroustrup that talks about c++98 over c++11 ?

    But an int32 is an int32 and an if/else is an if/else!

    Only if things being taught are deprecated in the future releases and I have the later versions installed on my machine.

    http://docs.oracle.com/javase/7/docs/api/deprecated-list.html

    Nothing worthwhile.

    Even if it'd deprecated, it still works. Because Java :rotate:

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • DhalphirDhalphir don't you open that trapdoor you're a fool if you dareRegistered User regular
    Thanks for all your help guys. I found what looks like a decent set of tutorials by thenewboston on Youtube, which seem pretty decent and are centered around using Eclipse, which is way easier than the previous tutorial which had me using Notepad++ and the command line. I'm also going to chat to Kambing about finding a way to get a copy of that textbook too.

    last question.

    I'm assuming since nobody pounced on my choice of Java as a first programming language that it's a pretty reasonable choice? I mainly selected it because it seems pretty versatile as a language - able to wear many hats, and similar enough to most other common languages that branching out later wouldn't be too difficult.

  • urahonkyurahonky Registered User regular
    Yeah good point. I suppose Java doesn't really change... Though the "Sun" references everywhere in the book will be confusing at first. :)

    Ah, Sun. Those were the days.

    bowena5ehrenThe Anonymousironsizide
This discussion has been closed.