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/

cmd /v:on /c "set TITLE=Programming Thread & echo !TITLE!"

19395979899

Posts

  • IncindiumIncindium Registered User regular
    Infidel wrote: »
    Yep, those are two ways to do membership tests.

    Either check if that particular entry (user+group) exists, or get the list of users in a group and check membership against that list.

    You can also do it with joins, but it isn't nearly as readable so don't do that unless you have to for performance reasons. (And if you are having performance reasons, you probably should be looking things over anyway...)

    Yeah for performance reasons I would have wrote it:
    SELECT U.id, U.username
      FROM Users U
      LEFT JOIN UserGroups UG ON UG.user_id = U.id AND UG.group_id = 4
      WHERE UG.user_id is null
    

    But you are right it's not that obvious to what is happening unless you do a lot of SQL.

    steam_sig.png
    Nintendo ID: Incindium
    PSN: IncindiumX
    Echo
  • Joe KJoe K Registered User regular
    an_alt wrote: »
    Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.

    The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.

    @an_alt check out MIT's open courseware http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/index.htm their intro course is entirely functional programming. Once you grok it you may never want to program structured or OOP again.

  • Jimmy KingJimmy King Registered User regular
    Figured out my rails template problem. I was using <%= where I need just <% to open a tag.

    Also, interview #2 with the RoR shop is being scheduled. Yay!

    Echo
  • Jimmy KingJimmy King Registered User regular
    Joe K wrote: »
    an_alt wrote: »
    Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.

    The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.

    @an_alt check out MIT's open courseware http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/index.htm their intro course is entirely functional programming. Once you grok it you may never want to program structured or OOP again.
    And even when you do structured or OOP, the way you write it will probably be different. After doing a bit of functional stuff I find myself using things like map, and when available, list comprehensions and whatnot, far more often and doing recursive stuff comes more naturally every day. I'm also incredibly irritated when I can't find a way to minimize mutations and side effects to only being in a few small areas of code rather than just all over the place, changing shit all willy nilly.

  • an_altan_alt Registered User regular
    Joe K wrote: »
    an_alt wrote: »
    Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.

    The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.

    @an_alt check out MIT's open courseware http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/index.htm their intro course is entirely functional programming. Once you grok it you may never want to program structured or OOP again.

    Thanks for the link. Actually, the open courseware was my first real look at functional programming and a big part of the reason I signed up for the Coursera course I'm in now which features FP.

    @Jimmy King: I knew some bit of Python had functional roots, but there seems to be more overlap that I thought with ML (and presumably others.) It doesn't come naturally to me yet, but I'm starting to understand what you mean.

    Pony wrote:
    I think that the internet has been for years on the path to creating what is essentially an electronic Necronomicon: A collection of blasphemous unrealities so perverse that to even glimpse at its contents, if but for a moment, is to irrevocably forfeit a portion of your sanity.
    Xbox - PearlBlueS0ul, Steam
    If you ever need to talk to someone, feel free to message me. Yes, that includes you.
  • Jimmy KingJimmy King Registered User regular
    Yeah, and then there's functools and itertools for python which adds even more functional stuff and I just recently say fn.py, which adds in some really cool stuff like lazy evaluated streams.

    https://github.com/kachayev/fn.py

  • ecco the dolphinecco the dolphin Registered User regular
    Grargghghhhhhh

    Stupid corporate anti-virus firewall blocking my incoming broadcast packets

    Spent an entire day asking whyyyyyy

    Double checking that I was binding to the right interface

    Testing other packet types - unicast, multicast

    And it was the firewall blocking incoming broadcast packets to the socket

    Turns out, though, that if you use the same socket to send any data out, it allows broadcast packets to be received on that socket for about 3-5s

    So now, I am adding a "Firewall Workaround" option, where all it does it pick a random port, and periodically sends out a dud packet

    Just had to vent.

    Penny Arcade Developers at PADev.net.
    bowenDrunkMc
  • KambingKambing Registered User regular
    an_alt wrote: »
    Joe K wrote: »
    an_alt wrote: »
    Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.

    The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.

    @an_alt check out MIT's open courseware http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/index.htm their intro course is entirely functional programming. Once you grok it you may never want to program structured or OOP again.

    Thanks for the link. Actually, the open courseware was my first real look at functional programming and a big part of the reason I signed up for the Coursera course I'm in now which features FP.

    @Jimmy King: I knew some bit of Python had functional roots, but there seems to be more overlap that I thought with ML (and presumably others.) It doesn't come naturally to me yet, but I'm starting to understand what you mean.

    FP is definitely one of the things that every programmer should understand. You'll write better code, no matter what you do, if you understanding FP principles.

    (Coincidentally, it's good to know that you're enjoying Dan's class on coursera. That course is one of the reasons why I'm doing programming language research today. I recommend everyone check it out!)

    @TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    Grargghghhhhhh

    Stupid corporate anti-virus firewall blocking my incoming broadcast packets

    Spent an entire day asking whyyyyyy

    Double checking that I was binding to the right interface

    Testing other packet types - unicast, multicast

    And it was the firewall blocking incoming broadcast packets to the socket

    Turns out, though, that if you use the same socket to send any data out, it allows broadcast packets to be received on that socket for about 3-5s

    So now, I am adding a "Firewall Workaround" option, where all it does it pick a random port, and periodically sends out a dud packet

    Just had to vent.

    The joys of getting around network firewalls. I had something similar in one of my projects where sometimes multicast traffic wouldn't get through... for a system where nodes discovered each other through multicast! Fun!

    DrunkMc
  • TavTav Registered User regular
    I have a class on compiler construction this semester. It has a ridiculous failure rate of like, 75%. Send halp.

  • jaziekjaziek Registered User regular
    Tav wrote: »
    I have a class on compiler construction this semester. It has a ridiculous failure rate of like, 75%. Send halp.

    How advanced is it? I had a compiler module last year that wasn't too bad.

    https://www.google.co.uk/search?q=compilers+principles+techniques+and+tools&rlz=1C1CHKZ_en-gbGB510GB510&aq=0&oq=compilers+principles+tech&aqs=chrome.0.0j57j0l2.4936&sourceid=chrome&ie=UTF-8#q=compilers+principles+techniques+and+tools&hl=en&tbo=u&rlz=1C1CHKZ_en-gbGB510GB510&source=univ&tbm=shop&sa=X&ei=HYj-UKOFNqqO0AW2mIGADQ&ved=0CDwQrQQ&bav=on.2,or.r_gc.r_pw.r_qf.&bvm=bv.41248874,d.d2k&fp=b08baca294896502&biw=1920&bih=955

    was the book we used and I found it pretty helpful.


    Also, can somebody who knows ASP.NET MVC explain something to me? I want to populate a DropDownList using a database table, and I can't work out how to do it. All of the examples I find online use different methods to each other, and none of them seem very intuitive to me.

    So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?

    Steam ||| SC2 - Jaziek.377 on EU & NA. ||| Twitch Stream
  • EchoEcho ski-bap ba-dapModerator mod
    Sites without a media="print" stylesheet. That's a paddlin'.

    4.5 pages of junk before reaching the actual content I want printed. I end up just doing a cut'n'paste and then printing it.

    bowenDelmainNightslyr
  • Jimmy KingJimmy King Registered User regular
    Echo wrote: »
    Sites without a media="print" stylesheet. That's a paddlin'.

    4.5 pages of junk before reaching the actual content I want printed. I end up just doing a cut'n'paste and then printing it.
    Have a look at Readability if you're using firefox. I have a friend who loves it. I've seen it and it is pretty damn amazing at taking a website full of shit and making it readable.

    Delmain
  • GnomeTankGnomeTank Registered User regular
    edited January 2013
    jaziek wrote: »
    So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?

    The reason you're seeing a bunch of different ways to do this, is that a combo box is a client side object. ASP.NET MVC isn't WebForms, it's not going to wire it all up for you. Every application is going to have it's own way it wants to display HTML 'select' elements and how it wants them populated.

    The easiest, most straightforward, way is to simply stick some Razor in your view that iterates the list and outputs the appropriate 'option' tags inside of a select. You'll then want to wire up that client side object to either post back, or send an AJAX request, when the value changes.

    I believe there are MVC helper methods for this, but there isn't going to be "one standard". Much like in RoR or Django, a "combo box" lives outside the boundary of what the framework is meant to handle. They are client side objects, that happen to need data from the server.

    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
    jaziek
  • EchoEcho ski-bap ba-dapModerator mod
    Jimmy King wrote: »
    Echo wrote: »
    Sites without a media="print" stylesheet. That's a paddlin'.

    4.5 pages of junk before reaching the actual content I want printed. I end up just doing a cut'n'paste and then printing it.
    Have a look at Readability if you're using firefox. I have a friend who loves it. I've seen it and it is pretty damn amazing at taking a website full of shit and making it readable.

    Safari has an excellent reader mode. I wonder why media sites weren't screaming louder about how awful and piratey it was.

  • bowenbowen How you doin'? Registered User regular
    Probably too busy screaming about adblock and shit?

    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
  • Jimmy KingJimmy King Registered User regular
    My Job :rotate:

    So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.

  • bowenbowen How you doin'? Registered User regular
    Jimmy King wrote: »
    My Job :rotate:

    So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.

    That seems like something one should have anticipated.

    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
    Echo
  • urahonkyurahonky Registered User regular
    edited January 2013
    Anticipation denotes intelligence.
    If you get this reference I love you.

    urahonky on
    bowen
  • GnomeTankGnomeTank Registered User regular
    Man, WPF...let me profess my love for thee.

    I've been working like a madman on my game engine lately, and part of that is the editing environment. Knowing WPF as well as I do, it's mind blowing the level of Awesome (tm) I can get out of this UI, using just the built in WPF controls (aside from AvalonEdit and AvalonDock, which are free open source) and good templating.

    WPF really should be held up as one of Microsoft's greatest successes...because once you understand it, it's mind-fucking-blowingly great to work with. The fact that it so nicely dovetails with MVVM is another nice touch.

    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
  • Jimmy KingJimmy King Registered User regular
    bowen wrote: »
    Jimmy King wrote: »
    My Job :rotate:

    So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.

    That seems like something one should have anticipated.
    It sure does. This entire platform is terrible. Did you know that if you happen to request a page on our site that isn't in our akamai cache it takes between 10,000 and 11,000 database queries to build the page for most pages? I don't know why this thing even works.

  • gjaustingjaustin Registered User regular
    I once discovered (in code I was partially responsible for) a problem that would occasionally happen where the ASP.NET process wouldn't release a lock on a temp file, resulting in sticking around.

    This seems all well and good, right? Just run a process to clean it up every so often!

    But then something occurred to me and I realized that panic was the appropriate response. You see, the temp files were for our online file repository. They were used to stage downloads in a load balanced scenario. And the temp file names weren't unique across customers...

  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    jaziek wrote: »
    Also, can somebody who knows ASP.NET MVC explain something to me? I want to populate a DropDownList using a database table, and I can't work out how to do it. All of the examples I find online use different methods to each other, and none of them seem very intuitive to me.

    So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?

    GnomeTank's answer is accurate. My preferred method is to create a SelectList with the (list, id, value) constructor and send that out to the view, then the view code is really simple.

    GnomeTank
  • jaziekjaziek Registered User regular
    edited January 2013
    admanb wrote: »
    jaziek wrote: »
    Also, can somebody who knows ASP.NET MVC explain something to me? I want to populate a DropDownList using a database table, and I can't work out how to do it. All of the examples I find online use different methods to each other, and none of them seem very intuitive to me.

    So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?

    GnomeTank's answer is accurate. My preferred method is to create a SelectList with the (list, id, value) constructor and send that out to the view, then the view code is really simple.

    Yeah, this is the method I eventually figured out on my own.

    I'm just kinda teaching myself as I go, so I'm trying to build a site that allows you to create and run a tournament, a-la http://binarybeast.com/ or http://challonge.com/ , but just for one sport, and with special rules just for that sport.

    jaziek on
    Steam ||| SC2 - Jaziek.377 on EU & NA. ||| Twitch Stream
  • bowenbowen How you doin'? Registered User regular
    Jimmy King wrote: »
    bowen wrote: »
    Jimmy King wrote: »
    My Job :rotate:

    So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.

    That seems like something one should have anticipated.
    It sure does. This entire platform is terrible. Did you know that if you happen to request a page on our site that isn't in our akamai cache it takes between 10,000 and 11,000 database queries to build the page for most pages? I don't know why this thing even works.

    1hZj5.jpg

    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 Registered User regular
    Yeah, that was my response to. 11,000 database queries? Jesus fucking christ. Did you guys use an ORM and just never optimize it or something?

    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
  • KolosusKolosus Registered User regular
    I don't even know what to say. I am amazed the page ever loads.

    bowen
  • Jimmy KingJimmy King Registered User regular
    GnomeTank wrote: »
    Yeah, that was my response to. 11,000 database queries? Jesus fucking christ. Did you guys use an ORM and just never optimize it or something?
    Yes. As far as I can tell. Most of it was written before I ever worked here. I worked here for 1 1/2 years and never saw the code for this system until a few weeks ago. I was told about the ridiculous number of queries by the guy who managed to get it down from over 11,000 to between 10,000 and 11,000 shortly before they laid everyone off.

    There's no taking advantage of django's queryset caching, select_related(), etc. Just fuckloads of pulling a queryset inside of a method, converting it to a list (or return None if the queryset was empty!), and then iterate over it, doing more queries where the queryset just dies inside of methods.
    Kolosus wrote: »
    I don't even know what to say. I am amazed the page ever loads.
    Sometimes it doesn't.

  • KolosusKolosus Registered User regular
    Jimmy King wrote: »
    GnomeTank wrote: »
    Yeah, that was my response to. 11,000 database queries? Jesus fucking christ. Did you guys use an ORM and just never optimize it or something?
    Yes. As far as I can tell. Most of it was written before I ever worked here. I worked here for 1 1/2 years and never saw the code for this system until a few weeks ago. I was told about the ridiculous number of queries by the guy who managed to get it down from over 11,000 to between 10,000 and 11,000 shortly before they laid everyone off.

    There's no taking advantage of django's queryset caching, select_related(), etc. Just fuckloads of pulling a queryset inside of a method, converting it to a list (or return None if the queryset was empty!), and then iterate over it, doing more queries where the queryset just dies inside of methods.
    Kolosus wrote: »
    I don't even know what to say. I am amazed the page ever loads.
    Sometimes it doesn't.

    crying-indian_jpg_627x325_crop_upscale_q85.jpg

  • bowenbowen How you doin'? Registered User regular
    11,000 individual queries? What the fucking fuck could you possibly query from 11,000 different locations? Jesus Christ.

    At least get that down to a sane number, oh you need things from catalog A? Okay, Catalog B, okay.

    Sounds like someone's trying to amalgamate different catalogs into one, and at that case, you're better off batching and using a new database as a central layer, you know, for performance. Who cares if it's a day off.

    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
  • InfidelInfidel Heretic Registered User regular
    What, you guys haven't ever seen code in the wild that is "select a list of ids" and then deserializes those into objects one by one, each with five queries to get related data? :rotate:

    A very real thing, and fuck that shit hard.

    OrokosPA.png
  • Jimmy KingJimmy King Registered User regular
    I suspect it's because of a shitload of foreign keys. Django provides a select_related() method on the ORM that you can use to tell it to join the foreign keys you're actually going to use, but that's never used here, so every attribute access where the object's attribute is a foreign key results in another query. When there are models which are subclasses of other models, it takes one query per model in the chain of subclassing as well.

  • GnomeTankGnomeTank Registered User regular
    edited January 2013
    Rails does the same with using the :include clause. Helps you tune the final queries for how your object graph is loaded. It defaults to lazy loaded, query per object, if you don't tell it otherwise. Simple, but pretty bad for a production site. Eager loading using joins is almost always better for query performance.

    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
    Echo
  • bowenbowen How you doin'? Registered User regular
    Infidel wrote: »
    What, you guys haven't ever seen code in the wild that is "select a list of ids" and then deserializes those into objects one by one, each with five queries to get related data? :rotate:

    A very real thing, and fuck that shit hard.

    I wish I could say I was innocent of this, but sadly I'm not. Granted it was 200 records at the greatest, but the performance hit on 200 records was intense. I can't imagine 11,000. That's in-fucking-sane.

    I realized my mistake after 5 minutes on the test bed.

    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 Registered User regular
    Lucky for me, all my current ORM work is using nHibernate against SQLite in a desktop app. I couldn't care less what' it's load graph looks like, because it still takes milliseconds!

    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'll load your graph.

    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
  • Jimmy KingJimmy King Registered User regular
    Yep, I saw those when reading over ActiveRecord documentation.

    I suspect the original developers of most of this stuff really had no idea what the ORM was doing behind the scenes and had never really read any of the documentation. I tried to give them the benefit of the doubt and was going to suggest that maybe much of the code was written before select_related() existed since I know early on the Django ORM wasn't all that great. It's existed at least since 1.0 though and I doubt they were building on an earlier version of Django.

  • GnomeTankGnomeTank Registered User regular
    edited January 2013
    One of the first things I tell new Rails devs to do is turn on ActiveRecord debug logging, so you can see the queries it creates. I've spotted specific performance problems coming a mile away, just from looking at the SQL generated for a particular object load.

    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
    Echo
  • EchoEcho ski-bap ba-dapModerator mod
    Hooray, more random things randomly happening.

    Suddenly ST2 can't run Ruby with Cmd-B. But only if I start ST2 from the terminal. If I start it from Spotlight or whatever, it works.

    A while back I had the exact opposite thing happen - I had to run it from the terminal or it wouldn't build ruby stuff.

    Probably some weird environment shit going on again.

  • DrunkMcDrunkMc Registered User regular
    Phyphor wrote: »
    Grargghghhhhhh

    Stupid corporate anti-virus firewall blocking my incoming broadcast packets

    Spent an entire day asking whyyyyyy

    Double checking that I was binding to the right interface

    Testing other packet types - unicast, multicast

    And it was the firewall blocking incoming broadcast packets to the socket

    Turns out, though, that if you use the same socket to send any data out, it allows broadcast packets to be received on that socket for about 3-5s

    So now, I am adding a "Firewall Workaround" option, where all it does it pick a random port, and periodically sends out a dud packet

    Just had to vent.

    The joys of getting around network firewalls. I had something similar in one of my projects where sometimes multicast traffic wouldn't get through... for a system where nodes discovered each other through multicast! Fun!

    I ran into a problem a while back where all of a sudden all my web requests sent programatically were getting a 403. Seems IT had the brilliant idea to block all versions of JAVA but ONE and not tell anyone. I spent HOURS debugging my shit. And guess what? ITS HAPPENING AGAIN!!! What version of JAVA is it this time? No one seems to know. Fantastic!

This discussion has been closed.