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/
Options

SELECT * FROM posts WHERE tid = 'PA PROGRAMMING THREAD'

15051535556100

Posts

  • Options
    SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    This is just a guess, but it looks like you're not using a parameterized ArrayList, right? So you'll need to cast the result from checklist.get(q) in order to treat it as the class you want. Your class is "parameter", I think, so try this:
    if (((parameter)checklist.get(q)).type != 1)
    

    borb_sig.png
  • Options
    CantidoCantido Registered User regular
    Saeris wrote: »
    This is just a guess, but it looks like you're not using a parameterized ArrayList, right? So you'll need to cast the result from checklist.get(q) in order to treat it as the class you want. Your class is "parameter", I think, so try this:
    if (((parameter)checklist.get(q)).type != 1)
    

    Ooh, so this gets the entire object (which is in fact "parameter"). That's the technique I need. Thank you.

    3DS Friendcode 5413-1311-3767
  • Options
    SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    edited March 2012
    Are you familiar with parameterization? That's often a better solution than just casting, as long as you're familiar with the concept.

    What you've got right now is an ArrayList which thinks it's storing plain old Objects. This works fine as long as you always remember to cast to the actual class, "parameter", whenever you want to manipulate an item in the list. That's what the "(parameter)" does: casts the Object to the type you want.

    Parameterization is the idea of telling the ArrayList that it's not just holding Objects, it's holding something more specific; the way you'd specify this is using angular brackets in the type name, such as ArrayList<Integer> or ArrayList<parameter>. When you reference this parameterized type, the return value from .get(), for example, will be of the type you gave (Integer, parameter, whatever) instead of just Object. That way you don't have to cast it at all; it's already the type you want.

    The usual convention in the Java API is to denote parameterized types with the letter 'E', such as in this ArrayList documentation: http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
    Omitting the bracketed type will always default it to Object, I believe.

    Saeris on
    borb_sig.png
  • Options
    Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited March 2012
    Eclipse usually complains if you don't use the generic/parameterized version of something when it exists. Or maybe that's the way I have it set up.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • Options
    CantidoCantido Registered User regular
    Eclipse usually complains if you don't use the generic/parameterized version of something when it exists. Or maybe that's the way I have it set up.

    I got the message to stick in (parameter) as said above. I was just hesitant on the meaning.

    Furthermore, because my main ArrayList of parameter objects is consistent throughout the program, I decided to just make my second array just a standard array of integers, rather than a second ArrayList. I'll match up the Arraylist index with what's in the integer array as needed. The first ArrayList is still a must.

    But hot damn is this project getting complicated.

    3DS Friendcode 5413-1311-3767
  • Options
    wildwoodwildwood Registered User regular
    Actually, if you declare the ArrayList as ArrayList<parameter>, you won't need to cast anything by sticking '(parameter)' in - the rest of your code should just work.

    Generics are fun, up until you get bit by type erasure.

    (And what's with the class with an all-lowercase name? Your chances of confusing it with a variable are high.)

  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    edited April 2012
    5 more days until the weekend.


    ...If a man wanted to learn Python for shits and giggles where would he start?
    e: I think that's what I want to learn next. Once I get this stupid Java certification complete, of course.

    urahonky on
  • Options
    EndEnd Registered User regular
    edited April 2012
    http://docs.python.org/tutorial/ - The (Official) Python Tutorial
    http://www.diveintopython.net/ - A python book that I've never actually really read, but it seems popular at least

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • Options
    TomantaTomanta Registered User regular
    Google has some excellent videos as well:
    http://code.google.com/edu/languages/google-python-class/

  • Options
    baronfelbaronfel Would you say I have a _plethora_?Registered User regular
    edited April 2012
    As I have been tinkering with the ruby koans to pick up that language, you may find the Python koans helpful.

    Basically you're provided a slew of source files and you run some entry point test file via the language's interpreter/compiler. It spits out an error message telling you which file to start in, and you investigate that file, which is filled with comments to teach you about the language. You modify that source file to fix the errors, then rerun the entry point to see if you were successful.

    baronfel on
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    You guys are the best. Thank you!

  • Options
    LuvTheMonkeyLuvTheMonkey High Sierra Serenade Registered User regular
    Seconding the nomination for that Dive Into Python one. It's a great tutorial if you already grok programming and OO concepts.

    Shame the author went nuts and deleted his entire presence off the Net - that's actually a mirror there.

    The official documentation is really good too - I didn't use too much of the tutorials, but the API/modules reference is very robust.

    Molten variables hiss and roar. On my mind-forge, I hammer them into the greatsword Epistemology. Many are my foes this night.
    STEAM | GW2: Thalys
  • Options
    InfidelInfidel Heretic Registered User regular
    PAdev.net renewals

    Quite a few people paid for 3 months, so this is a heads up that you'll be wanting to renew if you wish to keep your shell account shortly here.

    Thanks.

    OrokosPA.png
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    Phew my CEO just told me that he wants me to take my time on the Java cert retest so that I pass it. Said the bonus and reimbursement still applies as long as I take it within a month or so.

  • Options
    bowenbowen How you doin'? Registered User regular
    I don't think all the time in the world would prepare me for it so much as guessing how the JRE thinks.

    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
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    bowen wrote: »
    I don't think all the time in the world would prepare me for it so much as guessing how the JRE thinks.

    Oh it won't, but if my friend can get a 61 then so can I. I just cannot stick to reading the book and getting it. I need to do some examples and try out everything.

  • Options
    CantidoCantido Registered User regular
    Just ordered Head First C# to see what all the fuss is about.

    3DS Friendcode 5413-1311-3767
  • Options
    zeenyzeeny Registered User regular
    urahonky wrote: »
    5 more days until the weekend.


    ...If a man wanted to learn Python for shits and giggles where would he start?
    e: I think that's what I want to learn next. Once I get this stupid Java certification complete, of course.

    Programming in Python 3, 2nd ed by Summerfield.

  • Options
    seabassseabass Doctor MassachusettsRegistered User regular
    So, I got my copy of "The Little Lisper" in the mail over the weekend. I was flipping through it, glancing at the exercises and descriptions. I found, on page 13 in big bold letters "This space reserved for JELLY STAINS". I'm not sure if this is a programming manual or a misprint of the principia discordia. Learning lisp is going to be entertaining.

    Run you pigeons, it's Robert Frost!
  • Options
    CantidoCantido Registered User regular
    edited April 2012
    The jQuery Mobile version of my air conditioner thingy just successfully ajax posted for the first time. jQuery Mobile rocks. Eeeeeeeeeee :D

    Fuckin' internet.

    Cantido on
    3DS Friendcode 5413-1311-3767
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    Okay guys. I need your Google-fu expertise. Can anyone find a good example of wxNotebook ONLY in C++? There will be a few in Python. Also, not the sample: notebook.cpp (because I just need an example of how to make a notebook, and this thing has like 600 lines of code and it is impossible for me to read). (NOTE: wxNotebook is apparently their name for "tabbed panes")

    I have scoured the internets with search terms like "wxNotebook example", "wxNotebook example C++", "wxNotebook example C++ -python", etc. I just can't find a simple one that I can build off of.

  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    C++ question:
    MyGrid::MyGrid(wxNotebook * parent)
           : wxGrid(parent, wxID_ANY)
    {
      CreateGrid(30, 30);
      SetRowLabelSize(50);
      SetColLabelSize(25);
      SetRowLabelAlignment(wxALIGN_RIGHT, wxALIGN_CENTRE);
      SetLabelFont(wxFont(9, wxFONTFAMILY_DEFAULT, 
          wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
    
      for (int i = 0; i < 30 ; i++) {
          this->SetRowSize(i, 25);
      }
    
    }
    

    I don't understand what's going on in that function call. I'm assuming it's return type is a MyGrid? But it doesn't return anything... Is that another Class? (Looks at the .h file...) Yeah, it's another class. Okay so it's a MyGrid class... What about the colon after the parameters?

    : wxGrid(parent, wxID_ANY)

    Does that mean it's "extending" it? (I'm not even sure if extending exists in C++)

  • Options
    InfidelInfidel Heretic Registered User regular
    You are looking at the special function form of a constructor.

    The : wxGrid(parent, wxID_ANY) is a call to the superclass constructor to handle the base stuff. The code inside the function handles what is different for MyGrid.

    OrokosPA.png
  • Options
    bowenbowen How you doin'? Registered User regular
    That's a constructor ? MyGrid::MyGrid (A::B) is how you say "I'm defining MyGrid in the class MyGrid (defining B in class A)" : wxGrid is the parent class' constructor (I'm assuming MyGrid inherits from wxGrid) and then proceeds to define more data pertinent to it's own definition.

    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
  • Options
    bowenbowen How you doin'? Registered User regular
    Damn you @infidel.

    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
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    Infidel wrote: »
    You are looking at the special function form of a constructor.

    The : wxGrid(parent, wxID_ANY) is a call to the superclass constructor to handle the base stuff. The code inside the function handles what is different for MyGrid.

    Okay so it's basically saying super(parent, wxID_ANY) inside the function? (but in C++ terms)

  • Options
    InfidelInfidel Heretic Registered User regular
    urahonky wrote: »
    Infidel wrote: »
    You are looking at the special function form of a constructor.

    The : wxGrid(parent, wxID_ANY) is a call to the superclass constructor to handle the base stuff. The code inside the function handles what is different for MyGrid.

    Okay so it's basically saying super(parent, wxID_ANY) inside the function? (but in C++ terms)

    That is exactly what it is doing yes.

    OrokosPA.png
  • Options
    bowenbowen How you doin'? Registered User regular
    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
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    Fantastic. Thanks again guys. Going from Java to C++ back to Java back to VB has really rattled my brain.

  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    bowen wrote: »
    Java :rotate:

    I know I know... I keep bringing everything back to Java, but that's what I'm most comfortable with for now. I'm hoping to change that. But I get the feeling the longer I stick at a job that exclusively uses Java the longer I'll get stuck doing it because why would you hire someone who's never done Python even if he has more programming experience in another language.

  • Options
    seabassseabass Doctor MassachusettsRegistered User regular
    urahonky wrote: »
    bowen wrote: »
    Java :rotate:

    I know I know... I keep bringing everything back to Java, but that's what I'm most comfortable with for now. I'm hoping to change that. But I get the feeling the longer I stick at a job that exclusively uses Java the longer I'll get stuck doing it because why would you hire someone who's never done Python even if he has more programming experience in another language.

    Depends on the length of the hire and what you're hiring for. If you want a python guy, by all means, hire someone who is an ace at python. If you're hiring someone for their area expertise (security, databases, encryption, etc) then it becomes more difficult to bias hiring based on known languages.

    Run you pigeons, it's Robert Frost!
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    edited April 2012
    Another stupid question that I'm sure to be laughed at about: Say I have the following constructor:
    wxNotebook (wxWindow* parent, 
    wxWindowID id, 
    const wxPoint& pos = wxDefaultPosition, 
    const wxSize& size = wxDefaultSize, 
    long style = 0, 
    const wxString& name = wxNotebookNameStr)
    

    The only things I need to pass into it are: parent, and ID, right? The rest are defaults? Is it possible to have 5 parameters, 3 defaults set, but one of these defaults are at the beginning... Actually I'll use the above code as an example.
    wxNotebook (wxWindow* parent, 
    wxWindowID id = wxANY_ID, 
    const wxPoint& pos = wxDefaultPosition, 
    const wxSize& size, 
    long style = 0, 
    const wxString& name = wxNotebookNameStr)
    

    Using the above, if I did something like: wxNotebook *nb = new wxNotebook(panel, wxSize(500,500)), would that work? Would it know that I was using the defaults for everything else?

    e: I'm guessing not, since the compiler has no idea what I'm talking about when I do that. But it's worth an ask.

    urahonky on
  • Options
    bowenbowen How you doin'? Registered User regular
    Yes that should work.

    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
  • Options
    IncindiumIncindium Registered User regular
    You are going to need to do wxNotebook *nb = new wxNotebook(panel,,,wxSize(500,500)) I think since size is the 4th parameter...

    steam_sig.png
    Nintendo ID: Incindium
    PSN: IncindiumX
  • Options
    InfidelInfidel Heretic Registered User regular
    You can only have defaults at the end. You can't have a default parameter followed by a one without a default. You'd see why when you try to actually call the function, as you found out I guess with your edit comment.

    OrokosPA.png
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    Incindium wrote: »
    You are going to need to do wxNotebook *nb = new wxNotebook(panel,,,wxSize(500,500)) I think since size is the 4th parameter...

    I thought that might be the case. Since if your function takes in two integer parameters, how would it know which is which?

  • Options
    InfidelInfidel Heretic Registered User regular
    C is not one of those languages that allows empty arguments like that.

    OrokosPA.png
  • Options
    IncindiumIncindium Registered User regular
    edited April 2012
    Infidel wrote: »
    You can only have defaults at the end. You can't have a default parameter followed by a one without a default. You'd see why when you try to actually call the function, as you found out I guess with your edit comment.

    Crap it must be SQL where you can just use commas then to have it work they way I said. I haven't actively worked with C++ for 5-6 years so and have forgotten a ton.

    Incindium on
    steam_sig.png
    Nintendo ID: Incindium
    PSN: IncindiumX
  • Options
    urahonkyurahonky Resident FF7R hater Registered User regular
    Good to know again. Thanks :)

This discussion has been closed.