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/

YA[Programming]T :: Interview? That's an MVC thing, right?

12467100

Posts

  • bowenbowen How you doin'? Registered User regular
    edited May 2012
    Would be pretty neat to do something like this though, and have intellisense catch it:
    //collection of generic objects
    Dictionary<string,object> objectCollection = new Dictionary<string,object>();
    
    //instantiate my class & give it a name
    MyClass myObj = new MyClass();
    myObj.Name = "poopybutt";
    
    //get it's type
    Type T = myObj.GetType();
    
    //add it to the generic collection, by a key
    objectCollection.Add(myObj.Name,myObj);
    
    //dynamic recastObj = (T)objectCollection["poopybutt"];
    //what is this called below?  Duck Typing?
    var recastObj = (T)objectCollection["poopybutt"];
    Console.WriteLine("The object's name is {0}",recastObj.Name);
    

    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
  • bowenbowen How you doin'? Registered User regular
    You can kind of fake it with dynamic, but you run into runtime issues if you mistype. Not such a big deal, but it'd be great if you could.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Dynamic is neat, but it incurs the obvious overhead of any late-bound call, although it's generally better than reflection because the CLR is smart about cacheing the final bindings.

    Also, I can't program well without music. This is considered the norm in most programmer psychology circles, as programming is considered closest to music in the science <-> art spectrum. Many good programmers are also good musicians, or have a very good understanding of musical structure. Music is essential sound programming, so this makes sense.

    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
  • bowenbowen How you doin'? Registered User regular
    I mean... I know the type of the object at all points, but I just need an easy method to storing all different types of objects, and then recasting them back.

    I can do it manually, it's not tricky, I'd just like a keyword where I can go:
    List<object> myList = new List<object>();
    User userObject = new User();
    int someRandomNumber = 24;
    
    myList.Add(userObject);
    myList.Add(someRandomNumber);
    
    int thatNumber = MyList[1];
    User thatUser = MyList[0];
    
    

    That would be amazing to do. I can kind of fake it with dynamic but that's not the solution I want. It's just as easy to do this:
    User thatUser = (User)MyList[0];
    

    And not have to deal with dynamic at all. It sure would be nice if I didn't have to do that though, and it could assume I want the object in it's original form.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    You could use 'as', which is the preferred method as it doesn't throw an InvalidCastException on failure....though it can only be used with reference types and nullable value types.

    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
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    That seems to be asking a lot of the compiler. It doesn't really know that List.Add(userObject) then corresponds to List[0] without a ton of work; it's basically a variable rename, but why? It will stop working once the list is external, or modified, or non-local-scope because the compiler then can't really determine anything about the contents. And for what structures should it work?

  • bowenbowen How you doin'? Registered User regular
    Basically I'm trying to write as little as possible and wish C# would do an implied cast.

    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
    Phyphor wrote: »
    That seems to be asking a lot of the compiler. It doesn't really know that List.Add(userObject) then corresponds to List[0] without a ton of work; it's basically a variable rename, but why? It will stop working once the list is external, or modified, or non-local-scope because the compiler then can't really determine anything about the contents. And for what structures should it work?

    Well that's the thing C# does just fine at doing just that. The problem is it's runtime typecasting. I just want to do implied casting with intellisense because I'm lazy.

    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
    For instance:
    dynamic myUser = MyList[0];
    

    This works just fine, however if I do
    Console.WriteLine(myUser.Naem);
    

    It'd throw a runtime/reflection/cast (whatever it is specifically) exception because that's not defined. So long as I get my methods and members correct I can still do what I want to do but no longer have intellisense/compiler warnings to support my fumbles.

    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
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    Ah, so you want it to still do the cast, just without writing one

  • bowenbowen How you doin'? Registered User regular
    Phyphor wrote: »
    Ah, so you want it to still do the cast, just without writing one

    Yeah pretty much it. I can deal with casting though, that's no biggie. It's basically how I did this with null pointers back in the day anyways.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2012
    I guess I'm having trouble understanding why the C# compiler team would spend weeks (months?) creating a global implied cast system, just to save you from typing '(Type)' or 'as Type'.

    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
  • bowenbowen How you doin'? Registered User regular
    Because they hate themselves.

    Generics works though I suppose, doesn't save much typing:
    User aUser = MyList.At<User>(0);
    

    Ultimately what I'm trying to do is have a sessions system set up to be able to store random junk in there, but I just was getting sick of typing the type over and over when I already knew what it was.

    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
  • Joe KJoe K Registered User regular
    so, what's the procedure to get an account on padev.net?

  • bowenbowen How you doin'? Registered User regular
    Scream really loud and sacrifice a virgin at @urahonky's office?

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2012
    Send a message to @Infidel.

    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
  • bowenbowen How you doin'? Registered User regular
    Fine fine, take the easy way.

    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
    edited May 2012
    bowen wrote: »
    Scream really loud and sacrifice a virgin at @urahonky's office?

    What? It's not Monday. We can't do that today.

    urahonky on
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    admanb wrote: »
    omfg.

    I've realized I broke the back button in my web app I'm writing for databases class.

    I have become that which I have always hated!

    you son of a bitch

    what kind of broken?

    Eh, I'm just having a hard time reasoning about the relationship between URL's, the back button, and Session state.

    If I break the back button for this project I think it is okay, but since I want to keep working on it even after I turn it in for school, I would like to eventually wrap my head around it.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • centraldogmacentraldogma Registered User regular
    Use GET for everything :P

    When people unite together, they become stronger than the sum of their parts.
    Don't assume bad intentions over neglect and misunderstanding.
  • CantidoCantido Registered User regular
    edited May 2012
    Use GET for everything :P

    I don't knooooow. Using REQUEST saved my life in Senior Design. But that's because I was performing REQUESTs from horrible hardware :D

    Is it possible to take data from an electronically filled out PDF and store it onto a MySQL database? Or perhaps make a basic HTML form, store entries on a database, which can later populate a PDF? I'm working with Adobe Acrobat X at my new job and it's fantastic, and I'm wondering if this is something you can do. I'm actually going to make an e-signature version of an existing PDF form when their lawyers get back to me with what they need for an e-signature.

    Cantido on
    3DS Friendcode 5413-1311-3767
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    lol. I could have done it all ajax/rest, but I didn't.

    I'm using POST for forms. I use forms for choices that are more complex than "Here is a list of strings. Choose one". For those I use big touch-friendly buttons.

    But with webpy, forms with POST are functionally equivalent to GETs with "/url?foo=bar&cake=pie" queries, as far as getting the data out.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    The fact that you could have used a RESTful framework and didn't is shameful. Shameful I tell you.

    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
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    GnomeTank wrote: »
    The fact that you could have used a RESTful framework and didn't is shameful. Shameful I tell you.

    Well REST is for implementing a web API, right? But what I really needed was a web GUI, and I needed one fast, because this isn't web development class, it's a database class. I could have done it in Swing but, er, I'm not terribly fond of Java at this point.

    So if I had done REST, I would need to both create the REST app, and then the Web GUI on top of it.

    But yes, REST seems to be exactly designed for CRUD applications.

    *dies of shame*

    edit: I almost wrote it in Go. I'm kind of wishing I had because Webpy's documentation is spotty at best, and utter crap at worst.

    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
  • bowenbowen How you doin'? Registered User regular
    REST is useful for web GUIs I thought.

    I don't deal with web tech much because I dislike "The Cloud" as a concept and idea. Syncing with the cloud? Cool. Fine. Too much rests on my ability to get a quality internet connection. Even here at the office our internet goes out maybe once or twice a month... that's a whole lot of time and money we would waste. Plus they're slow as fucking balls most of the time compared to their local counterparts that sync when convenient.

    Ignore my rant though.

    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
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    bowen wrote: »
    REST is useful for web GUIs I thought.

    I don't deal with web tech much because I dislike "The Cloud" as a concept and idea. Syncing with the cloud? Cool. Fine. Too much rests on my ability to get a quality internet connection. Even here at the office our internet goes out maybe once or twice a month... that's a whole lot of time and money we would waste. Plus they're slow as fucking balls most of the time compared to their local counterparts that sync when convenient.

    Ignore my rant though.

    That's a valid rant. And also I have to admit my understanding of REST is very basic, but I think it is essentially using all the HTTP verbs semantically in an attempt to avoid session state. But how in the world to convince a web browser to do anything other than GET or POST, I haven't the faintest clue.

    This is supposed to be a Point of Sale system, and I'm sort of cloning the basic archetecture of the one we used at the Pizza place I used to work at, which had a headless linux box running a web server and database, and a bunch of boxes that functioned essentially as thin clients with touchscreens (even though they were still full-on P4-based celerons for some reason).

    The thing is THAT point of sale system was written very specific to IE6, and was also utter crap. In the end I want to see if I can do better.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2012
    REST is just a way to structure CRUD operations around HTTP verbs. Whether that's a JSON/XML based web service, or an actual web page, is irrelevant. It's just a way to structure VERB + URI = Action.

    GET /users would call the INDEX action of the users controller
    GET /users/1 would call the SHOW action of the users controller
    PUT /users?data=whatever would call the CREATE action

    etc etc.

    Whether or not those actions took in and returned some sort of web service protocal is irrelevant. Frameworks like Rails actually let you determine what to send back based on the request URI. So if they request GET /users it will return the rendered web page for the INDEX action. If they request GET /users.json, it will return rendered JSON for the INDEX action. This allows your controller code to stay almost identical, regardless of what the final output is. Rarely do you ever need to do special processing based on format, and when you do, you'll know it.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2012
    bowen wrote: »
    REST is useful for web GUIs I thought.

    I don't deal with web tech much because I dislike "The Cloud" as a concept and idea. Syncing with the cloud? Cool. Fine. Too much rests on my ability to get a quality internet connection. Even here at the office our internet goes out maybe once or twice a month... that's a whole lot of time and money we would waste. Plus they're slow as fucking balls most of the time compared to their local counterparts that sync when convenient.

    Ignore my rant though.

    That's a valid rant. And also I have to admit my understanding of REST is very basic, but I think it is essentially using all the HTTP verbs semantically in an attempt to avoid session state. But how in the world to convince a web browser to do anything other than GET or POST, I haven't the faintest clue.

    This is supposed to be a Point of Sale system, and I'm sort of cloning the basic archetecture of the one we used at the Pizza place I used to work at, which had a headless linux box running a web server and database, and a bunch of boxes that functioned essentially as thin clients with touchscreens (even though they were still full-on P4-based celerons for some reason).

    This thing is THAT point of sale system was written very specific to IE6, and was also utter crap. In the end I want to see if I can do better.

    Frameworks like Rails and Django use a hidden form input to tell the browser to do something other than POST and GET, specifically PUT and DELETE. More modern browsers actually support those keywords anyway.

    Basically the browser will still do a GET/POST, but Rails/Django internally will check that hidden variable/query value to determine whether they should really be doing a PUT or DELETE.

    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
  • bowenbowen How you doin'? Registered User regular
    Since I don't really understand REST at it's core, you're saying it's a system similar to a MVC, but with Server::Client archs?

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Oh, I should be careful here not to tie MVC and REST too closely together. While MVC is an amazing way to structure a RESTful app (and is the way that Django and Rails do things), it's not the only way. There are much lighter RESTful frameworks out there like Merb and Camping, which are essentially just routing engines.

    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
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    So basically my current url structure is:
    urls = (
        '/', 'login',
        '/logout', 'logout',
        '/manager', 'manager',
        '/sales', 'sales',
        '/sales/start_ticket', 'startTicket',
        '/sales/submit_ticket', 'submitTicket',
        '/sales/menu/([^/]+)/start', 'startItem',
        '/sales/menu/([^/]+)/submit', 'submitItem',
        '/sales/menu/([^/]+)/edit', 'editItem',
        '/sales/menu/([^/]+)/drop', 'dropItem',
        '/customer', 'customer'
    )
    

    The idea behind REST is that I would be able to replace all the urls like '/sales/menu/Pizza/edit' with just '/sales/menu/Pizza' and the action would depend on the HTTP verb in the request.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • bowenbowen How you doin'? Registered User regular
    Gotcha. I figured it was the better way to do it.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2012
    Yes, that's the very basic idea. Essentially frameworks like Rails are giant routing engines, that route VERB + URI combinations to actions in a controller. You can actually use Rails to do exactly what you're doing, just routing whatever URI's you want to whatever controller action's you'd like.

    REST just codifies it better, and allows frameworks like Rails to map known and defined combinations to known and defined actions, creating an easy to follow convention. Since Rails/Django/their ilk are all about convention over configuration, you can see why this works so well.

    Once I knew the Rails REST routing engine, I never had to think again about what action in my controller would be called for what URI. Give me the URI and the verb, and I can tell you exactly what action in my controller will be called, without ever looking at my routing configuration.

    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
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    And Webpy absolutely supports REST fundamentally. I mean my code for login is
    # Login handler
    class login:
        def GET(self):
            # If user has not logged in, show form
            if session.userid == 0:
                return render_nouser.login(False, loginForm())
            # otherwise redirect to the sales screen.
            else:
                raise web.seeother('/sales')
    
        # User has submited login creditials
        def POST(self):
            form = loginForm()
            match = False
            # Validation is manditory, even if there's no validation criteria.
            if form.validates():
                login = kpos_db.tryLogin(form['Username'].value, form['Password'].value)
                if login:
                    session.username = login['username']
                    session.userid = login['userid']
                    session.isManager = login['isManager']
                    session.currentTicket = False
                    if login['isManager']:
                        raise web.seeother('/manager')
                    else:
                        raise web.seeother('/sales')
            # If we got here there was a failure
            form['Password'].value = ''
            return render_nouser.login(True, form)
    

    So basically to support the other verbs for things where they make sense, it's as easy as
    class MenuItem:
        def GET(self):
            stuff()
    
        def POST(self):
            stuff()
    
        def PUT(self):
            stuff()
    
        def DELETE(self):
            stuff()
    

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2012
    Essentially, yes. The frameworks like Django and Rails just codify that, and because a verb can be used for more than one thing, it has to be mapped a bit different.

    GET for instance could be GET index or GET single item, depending on the URI that is passed to it.

    For instance, here is the rails routing table:

    GET /photos index display a list of all photos
    GET /photos/new new return an HTML form for creating a new photo
    POST /photos create create a new photo
    GET /photos/:id show display a specific photo
    GET /photos/:id/edit edit return an HTML form for editing a photo
    PUT /photos/:id update update a specific photo
    DELETE /photos/:id destroy delete a specific photo

    First part is the verb, second is the URI, third is the action to be called in the controller, and fourth is a description of what it would do in a typical web app.

    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
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Ah, but if the form is in /photos/new, when they POST it, won't the post request go to /photos/new and not /photos ?

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited May 2012
    You wouldn't call POST against /photos/new, in fact if you were doing pure RESTful resources, Rails wouldn't even route that call to anything. You GET /photos/new, which tells rails to run your new action, which effectively will return the HTML form to enter a new item.

    You would call POST against simply /photos, which would route to the create action, which is essentially "take the data entered in the form returned by the new action and create an actual database object from it".

    This same distinction exists between edit and update, where the edit action (GET /photos/:id/edit) returns the form to do the editing, while the update action (PUT /photos/:id) will update that object with the data provided in the form that edit returns.

    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
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    What I'm saying is that, assuming we're not using Ajax or jquery DOM insertions to jam a form into the webpage, when the user clicks the link to "/photos/new", they get a webpage with a form on it with "method=post", and when they submit the form, the brower's URL says "/photos/new" so the post goes to "/photos/new" right?

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    What I'm saying is that, assuming we're not using Ajax or jquery DOM insertions to jam a form into the webpage, when the user clicks the link to "/photos/new", they get a webpage with a form on it with "method=post", and when they submit the form, the brower's URL says "/photos/new" so the post goes to "/photos/new" right?

    In Rails, the browsers form url would just be "/photos" with a verb of POST. That would map to create, which is the sister action to new.

    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
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited May 2012
    Basically I should assume JQuery and Ajax, which is what Rails uses apparently.

    I can do that.

    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
This discussion has been closed.