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/

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

13468999

Posts

  • TofystedethTofystedeth Registered User regular
    Infidel wrote: »
    No language would cache that unless they have a way to designate functions as deterministic (a given parameter always returns the same value).

    This is not the case with the majority of code, since you usually aren't talking about functions in the mathematical sense but in the "check this string, whooops not deterministic" or have any kind of side effect that changes state.

    Use a variable. :)

    That's what I figured, I just didn't know if it was a thing where it could a variable and not modified, but I guess how does it know .find() is non-destructive.

    So here's a weird thing that happened in the same place I noticed that thing.
    One of the databases my corporate phone book site was using got moved to a different server. Since the actual initial source of the data had recently changed, some of the structure of the table I used also changed.
    One of the changes that two columns, specialty1 and specialty2, were now just specialties, delimited by commas.

    So I just use string.split and it works.

    Another column, degree, is for some reason now degrees. So instead MD or DDS, it might have several, sometimes different, sometimes just MD, MD, MD, MD, MD. I guess one for each they received.
    So I try string.split on that, and it just returns the whole string.
    Used the same delimiter set of just a comma both times.

    steam_sig.png
  • DaedalusDaedalus Registered User regular
    Infidel wrote: »
    No language would cache that unless they have a way to designate functions as deterministic (a given parameter always returns the same value).

    This is not the case with the majority of code, since you usually aren't talking about functions in the mathematical sense but in the "check this string, whooops not deterministic" or have any kind of side effect that changes state.

    Use a variable. :)

    In theory an optimizing compiler could catch that.

    In practice, don't trust the optimizer to do anything more than precalculate arithmatic expressions. Measure performance with a profiling tool.

  • TryCatcherTryCatcher Registered User regular
    On my programming Facebook groups this list is making the rounds.

    Top 5: C, Java, Obj-C, C++, C#, PHP.

    So there's that.

  • htmhtm Registered User regular
    bowen wrote: »
    Speaking of optimizing. If you have some code that looks like this
    string poopy = "buttsbuttsbuttsbutts";
    if(poopy.find("butts"))
    {
        print(poopy.find("butts"));
    }
    else
    {
        print(poopy.find("butts") + 1);
    }
    
    Does the (any/some/most?) compiler see all those identical calls to find and just put them in a variable to use as needed or does it do it each time?

    It depends on the language, but I don't think I've ever really seen them cache stuff like that.

    I think that any reasonably advanced compiler would probably catch that with common subexpression elimination/hoisting optimizations, especially if the string and the find function were designated const.

    CSE/value hoisting is a pretty ancient optimization technique. If the compiler has enough information to know that the find function won't cause side-effects when it's called, then the find calls will almost certainly be hoisted (assuming the compiler doesn't suck and some level of optimization is enabled).

  • quietjayquietjay Indianapolis, INRegistered User regular
    TryCatcher wrote: »
    On my programming Facebook groups this list is making the rounds.

    Top 5: C, Java, Obj-C, C++, C#, PHP.

    So there's that.
    So my X++ skills are even more obscure than visual FoxPro? I don't believe that.

    Become a Star Citizen
  • DaedalusDaedalus Registered User regular
    TryCatcher wrote: »
    On my programming Facebook groups this list is making the rounds.

    Top 5: C, Java, Obj-C, C++, C#, PHP.

    So there's that.
    Vala didn't even make the list. Sadface.

  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    TryCatcher wrote: »
    On my programming Facebook groups this list is making the rounds.

    Top 5: C, Java, Obj-C, C++, C#, PHP.

    So there's that.

    In programming we have two kinds of problems, cache invalidation, naming, and off by one errors

  • gavindelgavindel The reason all your software is brokenRegistered User regular
    Praise the light, my newest graphics project uses openGL. Here's to hoping that leads to a much easier assignment.

    Does anyone know how to set up a text input box in GL, GLU, or GLUT? The project requires that when the user presses 'N' that they get asked to provide a filename. I have the keybind working fine, but I can't find the function or mechanism for having a text pop up or input.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • TraceTrace GNU Terry Pratchett; GNU Gus; GNU Carrie Fisher; GNU Adam We Registered User regular
    https://www.youtube.com/watch?v=HF2F7y1VZP8

    Next version of NARS is in development. Here's a look!

  • djmitchelladjmitchella Registered User regular
    Sometimes I think there are not enough brackets in the world. Then I write code like this, and all is well:
     this.send('showModal', 'simple-modal-dialog',
            { title: Ember.I18n.t("A dialog about stuff"),
              items: [ { body: Ember.I18n.t("this stuff does things") } ] } );
    

    Those brackets are, from the outside in:
    • function call
    • object for function arguments (in this case we're only using two, but there's more optional parameters than we use here)
    • one of the arguments is an array of bits of dialog to show
    • the array contains objects -- again, in this case case we're only using one, but the dialog elements can also have a header or an image
    • the object contains a translated string
    so while it may seem like a lot, they all have a purpose -- but when we're doing the simplest-possible version of this function, it looks a bit goofy.

  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    If that looks completely normal to me does it mean I've done too much JS programming?

  • KambingKambing Registered User regular
    edited March 2015
    Sometimes I think there are not enough brackets in the world. Then I write code like this, and all is well:
     this.send('showModal', 'simple-modal-dialog',
            { title: Ember.I18n.t("A dialog about stuff"),
              items: [ { body: Ember.I18n.t("this stuff does things") } ] } );
    

    Those brackets are, from the outside in:
    • function call
    • object for function arguments (in this case we're only using two, but there's more optional parameters than we use here)
    • one of the arguments is an array of bits of dialog to show
    • the array contains objects -- again, in this case case we're only using one, but the dialog elements can also have a header or an image
    • the object contains a translated string
    so while it may seem like a lot, they all have a purpose -- but when we're doing the simplest-possible version of this function, it looks a bit goofy.

    It looks much more manageable with a bit more formatting:
    this.send('showModal', 'simple-modal-dialog',
      { title : Ember.I18n.t("A dialog about stuff")
      , items : [{ body : Ember.I18n.t("this stuff does things") }]
      });
    

    Kambing on
    @TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
  • djmitchelladjmitchella Registered User regular
    Oh, sure, but where's the fun in that? I never coded in Lisp, but every once in a while I like to imagine what it might be like. (I fiddled with emacs config way back when, but that doesn't really count)

  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited March 2015
    gavindel wrote: »
    Praise the light, my newest graphics project uses openGL. Here's to hoping that leads to a much easier assignment.

    Does anyone know how to set up a text input box in GL, GLU, or GLUT? The project requires that when the user presses 'N' that they get asked to provide a filename. I have the keybind working fine, but I can't find the function or mechanism for having a text pop up or input.

    None of those will do that. GL/GLU doesn't even really know about windowing. GLUT is pretty much output/window management only. Does it have to be OS-independent?

    Phyphor on
  • gavindelgavindel The reason all your software is brokenRegistered User regular
    Phyphor wrote: »
    gavindel wrote: »
    Praise the light, my newest graphics project uses openGL. Here's to hoping that leads to a much easier assignment.

    Does anyone know how to set up a text input box in GL, GLU, or GLUT? The project requires that when the user presses 'N' that they get asked to provide a filename. I have the keybind working fine, but I can't find the function or mechanism for having a text pop up or input.

    None of those will do that. GL/GLU doesn't even really know about windowing. GLUT is pretty much output/window management only. Does it have to be OS-independent?

    I have no idea. Suppose I'll ask the professor on Tuesday. His prompt only says "This command loads all the data and parameters from a text file. Hitting the "n" key should prompt the user for the name of the file.", so maybe I'm barking up the wrong tree.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    You could do it through the terminal in that case

  • urahonkyurahonky Registered User regular
    Anyone know if there's an API or something that I could call to get a list of purchased games of a particular steam user? I kinda want to make a randomizer that looks at all of your Steam games and randomly chooses 1-10 of them and you have to play it. Nothing fancy or anything just a fun little pet project but I can only find their Web API stuff which looks to let me link their steam login stuff to their site. Not quite what I was looking for... Didn't we have a PAer that made Steam signatures?

  • urahonkyurahonky Registered User regular
    https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29

    Ah. Damn it looks like I need to get a Web API key, which means I need a domain. :(

  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    honky.padev.net?

  • urahonkyurahonky Registered User regular
    Yeah I didn't really want to fully commit to doing the project lol. Just wanted some alone time with Python without spending moneys.

  • LD50LD50 Registered User regular
    That's a really cool project idea though, and you should totally do it.

  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    It doesn't sound like the domain actually matters though from reading the agreement

  • MNC DoverMNC Dover Full-time Voice Actor Kirkland, WARegistered User regular
    My brain is cramping from trying to figure out this assignment on figuring out the number of days old you are based on your birth date and the current day. The wife is knee deep in real coding work and master's degree homework so I don't wanna bother her.

    I think I need to step away from it and hopefully make heads or tails of it later. Even looking at what other people did to solve isn't helping. :(

    Need a voice actor? Hire me at bengrayVO.com
    Legends of Runeterra: MNCdover #moc
    Switch ID: MNC Dover SW-1154-3107-1051
    Steam ID
    Twitch Page
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    As with any programming problem, try to break it up.

    You're asked to find the number of days difference between two dates, so first of all, try calculating the number of days from 0 that a given date has.

    Breaking that up, you would calculate all the days for previous years, then add all the days for previous months, then the days for the current month

  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    My solution in the spoiler if you want it
    # calc # of days for all years up to and including y
    def yday(y):
        return y * 365 + (y / 4) - (y / 100) + (y / 400)
    
    def day_number(y, m, d):
        d += yday(y - 1) # days for previous years
        months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        if(m > 2 and y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d+=1 # if a leap year and past feb, add the leap day
        for i in range(m-1):
            d += months[i] # add in previous months
        return d
        
    
    def daysBetweenDates(year1, month1, day1, year2, month2, day2):
        ##
        # Your code here.
        ##
        return day_number(year2, month2, day2) - day_number(year1, month1, day1)
    

  • HamHamJHamHamJ Registered User regular
    MNC Dover wrote: »
    My brain is cramping from trying to figure out this assignment on figuring out the number of days old you are based on your birth date and the current day. The wife is knee deep in real coding work and master's degree homework so I don't wanna bother her.

    I think I need to step away from it and hopefully make heads or tails of it later. Even looking at what other people did to solve isn't helping. :(

    Well the real world answer is "use a well established datetime library".

    While racing light mechs, your Urbanmech comes in second place, but only because it ran out of ammo.
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    Seems like a pertinent time to link this again.

    borb_sig.png
  • djmitchelladjmitchella Registered User regular
    Three Panel Soul has another strip about coding today:
    2015-03-16-362.png

  • MNC DoverMNC Dover Full-time Voice Actor Kirkland, WARegistered User regular
    Phyphor wrote: »
    As with any programming problem, try to break it up.

    You're asked to find the number of days difference between two dates, so first of all, try calculating the number of days from 0 that a given date has.

    Breaking that up, you would calculate all the days for previous years, then add all the days for previous months, then the days for the current month

    The wife asked me to write out how I'd to it in a real-world scenario before creating any code. After doing so, I'm then supposed to transpose that into code.

    I know that I'll need to create a leapYearCheck procedure, which I did like so:
    def leapYearCheck(year1):
        if year1 == 0:
            return False
        if year1 % 4 == 0:
            if year1 % 100 == 0:
                if year1 % 400 == 0:
                    return True
                else:
                    return False
            return True 
        return False
    

    Now I've got a True/False check ready for the procedure calculating days. So I'm trying to wrap my head around making an efficient way to store the days in each month. My first thought was creating 12 variables, one for each month, and assigning them the proper day count. This is messy and a nightmare.

    Looking at your code, I can see that there's an easier way of getting the answer with lists and for loops, but I don't know how they work yet and I'm trying to solve this without using stuff that hasn't been introduced yet. :(

    Need a voice actor? Hire me at bengrayVO.com
    Legends of Runeterra: MNCdover #moc
    Switch ID: MNC Dover SW-1154-3107-1051
    Steam ID
    Twitch Page
  • bowenbowen How you doin'? Registered User regular
    I'd say, figure out how to do it without the leap year first.

    Leap year is an insignificant detail to the procedure.

    The best way to store the date is an array of ints corresponding to the day count.

    0-11, take the month's 'value' as an integer, subtract 1, and boom you've got your day count for each month.

    Once you've worked out how to get the total days without factoring in the leap year, then you can progress to it.

    I know a lot of courses grade on a pass/fail mechanism, but to me, I'd like to see your process on how you got there, and how you're doing it in code. I mean the assignment is pretty much titled "thinking critically."

    tl;dr - ignore leap year for now, get it working with your total days in each month calculations first.

    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
  • TofystedethTofystedeth Registered User regular
    edited March 2015
    HamHamJ wrote: »
    MNC Dover wrote: »
    My brain is cramping from trying to figure out this assignment on figuring out the number of days old you are based on your birth date and the current day. The wife is knee deep in real coding work and master's degree homework so I don't wanna bother her.

    I think I need to step away from it and hopefully make heads or tails of it later. Even looking at what other people did to solve isn't helping. :(

    Well the real world answer is "use a well established datetime library".
    Such as the one built into python.
    import datetime
    def daysBetweenDates(year1, month1, day1, year2, month2, day2):
        bdate = datetime.date(year1,month1,day1)
        today = datetime.date(year2,month2,day2) #or just datetime.date.today()
        return (today - bdate).days
    

    Tofystedeth on
    steam_sig.png
  • EtheaEthea Registered User regular
    On a side note I am going to be at GTC all week. So if anybody is in the San Jose area we should grab a drink :)

  • ecco the dolphinecco the dolphin Registered User regular
    Ethea wrote: »
    On a side note I am going to be at GTC all week. So if anybody is in the San Jose area we should grab a drink :)

    I guess you do know the way to San Jose, do do dooo dooo do do dooo dooo!

    Penny Arcade Developers at PADev.net.
  • crimsoncoyotecrimsoncoyote Registered User regular
    edited March 2015
    Had my review today.
    Apparently I need to make a more concerted effort to learn/use C++ though (investigating/fixing defects, working forward on new stuff coming down the pipe, etc), and I was basically told it would be a waste for me to focus on automation only (bye bye perl!)

    My manager is actually pretty happy with where I am now and where I'm headed it seems. He just wants to make sure I'm focusing on the right areas.

    So pretty good, all told. :D

    crimsoncoyote on
  • gavindelgavindel The reason all your software is brokenRegistered User regular
    Dammit, Euclid, stop having already proved what I just proved.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • ASimPersonASimPerson Cold... and hard.Registered User regular
    Ethea wrote: »
    On a side note I am going to be at GTC all week. So if anybody is in the San Jose area we should grab a drink :)

    @Ethea what's up

  • urahonkyurahonky Registered User regular
    At the hospital right now. Wife is having some major contractions. Is this when everything gets pushed into master? We'll see!

  • gavindelgavindel The reason all your software is brokenRegistered User regular
    urahonky wrote: »
    At the hospital right now. Wife is having some major contractions. Is this when everything gets pushed into master? We'll see!

    Remember: 90% of the cost of code is maintenance.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • TraceTrace GNU Terry Pratchett; GNU Gus; GNU Carrie Fisher; GNU Adam We Registered User regular
    urahonky wrote: »
    At the hospital right now. Wife is having some major contractions. Is this when everything gets pushed into master? We'll see!

    for what it's worth

    NARS just put together this a few moments ago.
    <(&,{D},{A},{D})-->Word>.
    

    Probably completely random chance.


    Right?

  • urahonkyurahonky Registered User regular
    Looks like we're either going to induce or break her water and go from there. As long as no one rebases we should be good! I'll post more in the days to come.

This discussion has been closed.