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/

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

15556586061100

Posts

  • bowenbowen How you doin'? Registered User regular
    Lux782 wrote: »
    using(MyClass obj =MyClass(stuff))
    {
        obj.PerformAction();
        while(obj.Results().Read())
        {
        // do stuff
        }
    }
    

    I still don't like that...This appears to do lots of stuff. I would probably attempt to refactor it out more, potentially into its own class. You essentially have 2 actions you are doing. First you are doing something then you processing the results of that action.
    // calling code
    using(MyClassProcessor process = new MyClassProcessor(new MyClass(stuff))
        process.Run();
    
    class MyClassProcess : IDisposable
    {
        private MyClass myClass;
    
        public MyClassProcess(MyClass obj)
        {
            myClass = obj;
        }
    
        public void Dispose()
        {
            myClass.Dispose();
        }
    
        public void Run() {
            DoAction();
            ProcessResults();
        }
    
        private void DoAction();
        private void ProcessResults(); // If this is really complex it might be worth while breaking out into its own class
    }
    

    Probably could refactor out more stuff, if the pattern is repeated as often as you say, you may be able to abstract a lot of things out and get some good reuse out of it.


    I'd disagree. Generally you have to iterate through the results either way. Mostly this is a UI attachment so iterating through it is to show it on the screen in some fashion. In this case it tosses it in a list view from an array.

    But that's been changed .PerformAction() returns an array of objects and then I do :
    ListView.Items.AddRange(obj.PerformAction());
    

    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
    Okay I've run into a snag and I'm hoping someone here can help out.

    I used a Scene (which is imported from org.netbeans.api.visual.widget.Scene) as a tabbed pane component. Mainly because I need to be able to drag/drop a widget into it. I've tested it, and it works. I'm able to put two tabs, each with Scenes and change the background color of each and they show up properly.

    The problem now is adding to that Scene. I thought using tabbedPane.getSelectedComponent() would give me a Scene since that's the component inside. But it doesn't. This is the code I'm using:
    System.out.println("CLASS: " + getJTabbedPane().getSelectedComponent().getClass());
    

    This outputs:
    CLASS: class org.netbeans.api.visual.widget.SceneComponent

    So I figure I could typecast the SceneComponent to a Scene, right? Nope. When I do that I get an inconvertable types error. Then I try to typecast it as a SceneComponent, but it doesn't know what a SceneComponent is. So I'm stuck. How do I get the original scene that is inside the tabbed pane?

  • bowenbowen How you doin'? Registered User regular
    They're both widgets, can't you look for a widget instead of Scene?

    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
    Same error somehow. It says "Cannot covert Component to Widget". Which is weird because when I output the class of the component it comes out as a SceneComponent.

  • urahonkyurahonky Registered User regular
    I feel like I need to extend JTabbedPane and basically allow the tabs to accept a scene and be able to return a scene.

  • bowenbowen How you doin'? Registered User regular
    What if you accept component instead of widget? :P

    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
    bowen wrote: »
    What if you accept component instead of widget? :P

    I'm not sure what you mean. Are you talking about error checking? :) I am going to be the only one using this Tabbed Pane class.

  • bowenbowen How you doin'? Registered User regular
    edited April 2012
    Change the expected type? I don't know. You should be able to use them as their parent class, so if you can add a tab as a widget, express it as the most unique object of the hierarchy.

    In your case Scene and SceneComponent are both of "widget" type. Use that as the object you use to add a tab. Obviously you made your function accept a Scene type object right? Change that. This is the power of polymorphism.
    //function to add widgets as tabs
    private void addTab(Widget TheWidget)
    {
        //add it to the window here?
    }
    
    public void DragDropPassEventThing(//yadda)
    {
        //somewhere else
        Widget tabWidge1 = new Scene("Tab1");
        Widget tabWidge2 = new SceneComponent("Tab2");
    
        this.addTab(tabWidge1);
        this.addTab(tabWidge2);
    }
    

    This way your function can take either of those types of components and use them as tabs.

    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
    bowen wrote: »
    Change the expected type? I don't know. You should be able to use them as their parent class, so if you can add a tab as a widget, express it as the most unique object of the hierarchy.

    In your case Scene and SceneComponent are both of "widget" type. Use that as the object you use to add a tab. Obviously you made your function accept a Scene type object right? Change that. This is the power of polymorphism.
    //function to add widgets as tabs
    private void addTab(Widget TheWidget)
    {
        //add it to the window here?
    }
    
    public void DragDropPassEventThing
    {
        //somewhere else
        Widget tabWidge1 = new Scene("Tab1");
        Widget tabWidge2 = new SceneComponent("Tab2");
    
        this.addTab(tabWidge1);
        this.addTab(tabWidge2);
    }
    

    This way your function can take either of those types of components and use them as tabs.

    This would work except I need scenes because I am going to be adding the Widgets TO that scene. Each tab will have it's own Scene with it's own Widgets on that scene. Scene is the parent of all the Widgets... Hopefully this makes sense. So far my SceneTabbedPane is working like a champ.

  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    Anyone have a comprehensive link to how do deal with array values in querystrings in MVC3?

    such as:

    &filter[filters][0][value]=thing

  • bowenbowen How you doin'? Registered User regular
    Clearly something is converting your scene into scenecomponents then urahonkey, or it was designed to prevent someone doing what you're doing without doing it the way I'm showing.

    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
    bowen wrote: »
    Clearly something is converting your scene into scenecomponents then urahonkey, or it was designed to prevent someone doing what you're doing without doing it the way I'm showing.

    Yeah I'm not sure what/why/how it's doing that, honestly.

  • centraldogmacentraldogma Registered User regular
    org.netbeans.api.visual.widget.SceneComponent isn't even listed in the Netbeans API. Like, it's not even listed as existing...

    When people unite together, they become stronger than the sum of their parts.
    Don't assume bad intentions over neglect and misunderstanding.
  • baronfelbaronfel Would you say I have a _plethora_?Registered User regular
    edited April 2012
    I should have asked you guys before blindly choosing a mocking framework for java :(

    I initially went with Jmock based on nothing more than google result listings, but a friend just introduced me to Mockito, which looks to be about 100x more streamlined, and more along the lines of Rhino.Mocks, which I use for my .Net work.

    Anywho, just thought I'd toss that out for general informative purposes.

    PS - Explaining why mocking and unit testing is in general a good thing for verification and validation to someone who has hobby coded, but nothing of any real size, since before I was out of diapers is surprisingly hard.

    baronfel on
  • 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
  • baronfelbaronfel Would you say I have a _plethora_?Registered User regular
    Unrelated:

    I just watched this talk on creating a bridge between Java bytecode and the .Net CLR. The main thrust is IKVM lets you use libraries from Java in .Net nearly seamlessly.

    Keep an eye out towards the end for the presenter running Eclipse, on the CLR faster than the original Java-bytecode parent.

  • urahonkyurahonky Registered User regular
    org.netbeans.api.visual.widget.SceneComponent isn't even listed in the Netbeans API. Like, it's not even listed as existing...

    Yep. I looked at the API as well. :P

  • bowenbowen How you doin'? Registered User regular
    SceneComponent seems to be an underlying class involved in things like GraphScene that devs can't/shouldn't touch.

    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
    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
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    Huh. The regex one granted me some new insight. I didn't know about non-capturing groups.

    borb_sig.png
  • urahonkyurahonky Registered User regular
    Ugh... It's "Serif" not "Sareef"

  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Well...yeah, because serif is a word and sereef is not :P

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    Sareef is almost, but not quite, a Middle-Eastern/Indian name.

  • urahonkyurahonky Registered User regular
    Just a pet peeve of mine. That and "Libary" instead of "Library".

  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited April 2012
    Who in the world says/types "libary"?

    GnomeTank on
    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    GnomeTank wrote: »
    Who in the world says/types "libary"?

    I said libary a lot... when I was around the age of 12.

  • urahonkyurahonky Registered User regular
    Almost everyone in this room says "libary" and it literally kills me inside.

  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    urahonky wrote: »
    Almost everyone in this room says "libary" and it literally kills me inside.

    I am sure it's not completely true, but you do an excellent job of making everyone you work with sound like a mouth breathing pants on head idiot.

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • seabassseabass Doctor MassachusettsRegistered User regular
    edited April 2012
    admanb wrote: »
    Sareef is almost, but not quite, a Middle-Eastern/Indian name.

    With my deepest apologies
    18000469.jpg

    seabass on
    Run you pigeons, it's Robert Frost!
  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    Goddamn.

  • urahonkyurahonky Registered User regular
    GnomeTank wrote: »
    urahonky wrote: »
    Almost everyone in this room says "libary" and it literally kills me inside.

    I am sure it's not completely true, but you do an excellent job of making everyone you work with sound like a mouth breathing pants on head idiot.

    Hah. No comment.

  • urahonkyurahonky Registered User regular
    Truth be told I'm not very intelligent. I just learn to adapt. :P

  • TrippyJingTrippyJing Moses supposes his toeses are roses. But Moses supposes erroneously.Registered User regular
    edited April 2012
    I've got a bit of a problem. I have a project which makes use of a Library class. The class has two vector member variables which are manipulated with the member functions, but this isn't happening. I'm fairly certain I fucked up the constructor somehow, since every time I debug it, the vectors are destroyed immediately upon calling a member function.
    Library::Library()
    {
    	int numCards = 0;
    	int numBooks = 0;
    	std::vector<Book> booklist;
    	std::vector<Card> cardlist;
    }
    
    Library::Library(std::string file1, std::string file2)
    {
    	int numCards = 0;
    	int numBooks = 0;
    	std::vector<Book> booklist;
    	std::vector<Card> cardlist;
    
    	std::ifstream inBook, inCard;
    
    	inBook.open(file1.c_str());
    	inCard.open(file2.c_str());
    
    	std::string title;
    	std::string author;
    	std::string ISBN;
    	std::string status;
    	std::string holderID;
    
    	std::string name;
    	std::string phone;
    	std::string cardID;
    	std::string bookID;
    
    	do
    	{
    		if (!inBook.eof())
    		{
    			getline(inBook, title);
    			getline(inBook, author);
    			getline(inBook, ISBN);
    			getline(inBook, status);
    			getline(inBook, holderID, '\n');
    
    			Book tempbook(title, author, ISBN, status, holderID);
    			booklist.push_back(tempbook);
    			numBooks++;
    		};
    	}
    	while (!inBook.eof());
    
    	do
    	{
    		if (!inCard.eof())
    		{
    			getline(inCard, name);
    			getline(inCard, phone);
    			getline(inCard, cardID);
    			getline(inCard, bookID, '\n');
    
    			Card tempcard(name, phone, cardID, bookID);
    			cardlist.push_back(tempcard);
    			numCards++;
    		};
    	}
    	while (!inCard.eof());
    
    	std::vector<Book>::iterator it;
    
    	for (it=booklist.begin(); it<booklist.end(); it++)
    	{
    		std::cout << it->getTitle() << std::endl;
    		std::cout << it->getAuthor() << std::endl;
    		std::cout << it->getISBN() << std::endl;
    		std::cout << it->getStatus() << std::endl;
    		std::cout << it->getHolder() << std::endl << std::endl;
    	};
    }
    

    TrippyJing on
    b1ehrMM.gif
  • ecco the dolphinecco the dolphin Registered User regular
    TrippyJing wrote: »
    I'm fairly certain I fucked up the constructor somehow, since every time I debug it, the vectors are destroyed immediately upon calling a member function.

    Sort of. By doing:
    Library::Library()
    {
    	int numCards = 0;
    	int numBooks = 0;
    	std::vector<Book> booklist;
    	std::vector<Card> cardlist;
    }
    

    You're creating numCards, numBooks, booklist and cardlist as local variables in the constructor, not member variables of the class.

    Compare with:
    void testFunction( void )
    {
    	int localCopy; // This variable only exists in testFunction()
    }
    

    This is what you're doing. This is why you are seeing the vectors being destroyed after calling the constructor... and I suspect that you've made the same mistake in the member functions.

    To use member variables instead of creating local variables:
    Library::Library()
    {
    	numCards = 0; // They already exist
    	numBooks = 0;
    }
    

    assuming that you declared them in the Library class by doing something like:
    class Library
    {
    public:
    	// ...
    
    private:
    	int numCards, numBooks;
    	std::vector<Book> booklist;
    	std::vector<Card> cardlist;
    };
    

    Penny Arcade Developers at PADev.net.
  • TrippyJingTrippyJing Moses supposes his toeses are roses. But Moses supposes erroneously.Registered User regular
    That is exactly how I had them declared, and it seems I fundamentally misunderstood constructors.

    Thanks! That solves my main problem, and now I just have to write up the documentation and I'm done.

    b1ehrMM.gif
  • [Michael][Michael] Registered User regular
    Corona SDK seems like it's pretty awesome for the projects it can do (though I do see its limitations). I spent maybe a month of on and off free-time learning Android and making an app, and I managed to recreate it in Corona in 3 days. Might be worth it to shell out the 400 dollars or whatever for it if it means being able to publish to iOS and Android.

    Plus, Lua is pretty fun compared to Java. It's at least a nice break.

  • Mike DangerMike Danger "Diane..." a place both wonderful and strangeRegistered User regular
    So my friend suggested I try Readability in lieu of Instapaper. However, as far as I can tell, there isn't an easy "import your articles from Instapaper to Readability" service. "I know," I said last night, "I'll use Ruby to handle this!"

    Sure enough, Readability has an associated gem for their library (Readit); however, Readit assumes that you have an access token/secret before you start. I decided to try doing this with XAuth and I'm not sure what I'm doing wrong:
    require 'highline/import'
    require 'yaml'
    require 'oauth'
    require 'readit'
    
    config = YAML.load_file("config/readability.yaml")
    uname = ask ("Username: ") 
    passwd = ask ("Password: ") {|q| q.echo = false}
    
    consumer = OAuth::Consumer.new(config["-consumer_key"], config["-consumer_secret"], :site => "https://www.readability.com/api/rest/v1/oauth/access_token/")
    access_token = consumer.get_access_token(nil, {}, {:x_auth_mode => 'client_auth', :x_auth_username => uname, :x_auth_password => passwd})
    

    Running this and giving my username/password gets me:
    /Users/mike/.rvm/gems/ruby-1.9.3-p125/gems/oauth-0.4.5/lib/oauth/consumer.rb:219:in `token_request': 404 NOT FOUND (OAuth::Unauthorized)
    	from /Users/mike/.rvm/gems/ruby-1.9.3-p125/gems/oauth-0.4.5/lib/oauth/consumer.rb:109:in `get_access_token'
    	from instab.rb:15:in `<main>'
    

    I'm not sure what I'm doing wrong. That URL to readability's site seems to be right, and uname and passwd have the values I expect them to have before I make the get_access_token call.

    Steam: Mike Danger | PSN/NNID: remadeking | 3DS: 2079-9204-4075
    oE0mva1.jpg
  • Jimmy KingJimmy King Registered User regular
    I haven't messed with xAuth, but in the standard OAuth flow there's a callback URL on your own side which you pass to the server during the token request process and the server will redirect the user back to that URL and some more stuff is done there. Does xAuth also need that? With twitter and yahoo to not use it you pass "oob" as the callback URL. That would be my first guess as to what's going wrong, not being familiar with any differences xAuth has over OAuth other than that you pass in the username and password yourself.

    Other than that, look at the line in the code it's specifying is causing the error to see what URL it might be trying to access and where that comes from is my advice.

  • Lux782Lux782 Registered User regular
    For those who are interested in cool stuff.

    http://0x10c.com/doc/dcpu-16.txt

    Its a 16bit assembler spec for a new game Notch is apparently working on.

This discussion has been closed.