Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

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

1910121415100

Posts

  • InfidelInfidel Heretic Registered User regular
    It's not recursion. Using the same method name but different parameter types is overloading.

    The Builder abstract class just sets up the friendlier append methods (that accept full strings or arbitrary objects instead of just a character) just leaving you to implement what append(char) means. In this case, it's to add to a StringBuffer in a particular way.

    TwitchTV channel: OrokosPA OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • VerboseVerbose Registered User regular
    That problem isn't the issue anymore. Now I and my classmate whom I am discussing it with, are pretty much clueless on the other problem I posted, for a variety of reasons.

    steam_sig.png
  • InfidelInfidel Heretic Registered User regular
    I wasn't addressing the problem but your misunderstanding of what recursion is.

    That would bite you in the ass big time soon enough.

    TwitchTV channel: OrokosPA OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • VerboseVerbose Registered User regular
    I do get recursion although I would be entirely unsurprised to learn I used a bad example. I'm kind of all over the place right now trying to understand this.

    steam_sig.png
  • InfidelInfidel Heretic Registered User regular
    My point stands then. :)

    TwitchTV channel: OrokosPA OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • zeenyzeeny Registered User regular
    I want my life back
    the days before recursion
    blew my mind away

  • LindenLinden Registered User regular
    edited February 2012
    Verbose wrote: »
    Does the pw.println somehow pass the input through the write method or something?

    Yes. The PrintWriter is really handy for this: It breaks down the input string, then runs the writer's write method on the resultant bytes (the default is internally a loop over the array calling the single-byte version - you can find implementations in OpenJDK if you're interested, but it's not needed).

    For this problem, concern yourself with overriding the behavior of OutputStream#write(int), with general contract
    wrote:
    Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

    Other refs:
    Spoiler:

    E: goddamn automatic quote linking

    Linden on
    What if this weren't a rhetorical question?
  • [Michael][Michael] Registered User regular
    I thought I had a good handle on how to use recursion and what it can do after Programming Foundations II, then I was introduced to Scheme in Programming Paradigms and dynamic programming in Algorithms. Now it just hurts my brain even more.

  • Grey PaladinGrey Paladin Registered User regular
    Recursion is a war crime. Also animal abuse. If the call stack was an animal.

    "All men dream, but not equally. Those who dream by night in the dusty recesses of their minds wake in the day to find that it was vanity; but the dreamers of the day are dangerous men, for they may act their dream with open eyes to make it possible." - T.E. Lawrence
  • iTunesIsEviliTunesIsEvil Registered User regular
    baronfel wrote: »
    In a week or so the Visual Studio 11 preview will drop, and it's coming with c++ '11, I think. More info here, and a dev diary here.

    I'm really liking the new UX/chrome in VS'11.

  • Shazkar ShadowstormShazkar Shadowstorm Registered User regular
    figure here would be a good place to ask

    need to brush up on algorithms / be able to write some basic pseudocode for an interview

    won't need to know in depth technical stuff as it's not a programming position, but technical knowledge is needed

    haven't looked at this stuff in a few years, since data structures... where is a good place / what is a good way to review

    | Steam & XBL: Shazkar | 3DS: 3110-5421-3843 | SS Wishlists |
  • VerboseVerbose Registered User regular
    edited February 2012
    I did finally manage to complete the problem. I just want to especially thank Linden because that stuff you posted helped a lot.

    Verbose on
    steam_sig.png
  • GnomeTankGnomeTank Registered User regular
    Lambda recursion is the best
    public static MethodInfo[] GetInterfaceMethods (this Type iface, BindingFlags flags) {
    	if (!iface.IsInterface) {
    		throw new ArgumentException ("Type must be an interface", "iface");
    	}
    
    	var methods = new List<MethodInfo> ();
    	Action<Type> getInterfaceMethods = null;
    	getInterfaceMethods = t => {
    		methods.AddRange (t.GetMethods (flags));
    		foreach (var childIface in t.GetInterfaces ()) {
    			getInterfaceMethods (childIface);
    		}
    	};
    
    	getInterfaceMethods (iface);
    	return methods.Distinct ().ToArray ();
    }
    

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh
  • InfidelInfidel Heretic Registered User regular
    VARIADIC TEMPLATE RECURSION YESSSSSSSS

    TwitchTV channel: OrokosPA OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • [Michael][Michael] Registered User regular
    figure here would be a good place to ask

    need to brush up on algorithms / be able to write some basic pseudocode for an interview

    won't need to know in depth technical stuff as it's not a programming position, but technical knowledge is needed

    haven't looked at this stuff in a few years, since data structures... where is a good place / what is a good way to review

    Assuming you've got some time, this book is just about regarded as the bible for algorithms. For all the algorithms they go over in the book, they give a pseudocode implementation. However, it's a very technical book. And it's like 1300 pages. But, if this is material you've already studied before, it could be a good refresher to skim through to the relevant parts you don't really remember/understand. I say relevant parts, because it's very comprehensive.

    It's also a good book just to keep around for referencing.

  • IzzimachIzzimach Storm-Wizard Registered User regular

    Thanks for the info guys, I'll see what kind of monstrosity I can hack up. As GnomeTank mentioned, writing a MOBA backend in Javascript will be pretty disgusting. The concept is interesting to me because it allows the use of Javascript on both server and client. Also, I'm curious about the actual performance of Google's V8 engine. I'd better go read that Eloquent Javascript book first, though.

  • InfidelInfidel Heretic Registered User regular
    Izzimach wrote: »
    Thanks for the info guys, I'll see what kind of monstrosity I can hack up. As GnomeTank mentioned, writing a MOBA backend in Javascript will be pretty disgusting. The concept is interesting to me because it allows the use of Javascript on both server and client. Also, I'm curious about the actual performance of Google's V8 engine. I'd better go read that Eloquent Javascript book first, though.

    Javascript and V8 are very reasonable.

    They're not C fast but hey, they are powerful and fast still.

    Give it a go and let us know how it goes!

    TwitchTV channel: OrokosPA OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • FreeAgentFreeAgent Registered User regular
    Is anyone familiar with generating PCM sound in Xcode using C? I ask because I've been looking over the api for an hour and feel like I don't know what the hell is going on.

    [SIGPIC][/SIGPIC]
  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    edited February 2012
    Today I got to experience the...endless joy...of getting MySQL-python to work on Windows. Since I'm now in a "good" mood, I'm just going to leave these instructions here so nobody else has to waste hours of their time on this shit.
    Spoiler:

    The Anonymous on
    camo_sig.png
  • zeenyzeeny Registered User regular
    edited February 2012
    As GnomeTank mentioned, writing a MOBA backend in Javascript will be pretty disgusting

    If it is, it won't be Javascript's fault. <img class=" title=":lol:" class="bbcode_smiley" />
    Also, I'm curious about the actual performance of Google's V8 engine. I'd better go read that Eloquent Javascript book first, though.

    I'm not familiar with Eloquent Javascript, so it's entirely possible that it's actually a better book, but my recommended reading will (again) be Crockford - Javascript: The Good Parts. It's brief, to the point, for programmers and it does well to introduce some current common practices of writing JS code. It may be about to start getting dated, but I found it exactly what I needed at the time. Very fast, very easy read.

    zeeny on
  • jackaljackal Registered User regular
    edited February 2012
    Recursion is a war crime. Also animal abuse. If the call stack was an animal.

    Recursion is the best for problems that involve self similar data structures.

    For more information read this comment.

    jackal on
  • JasconiusJasconius sword criminal Flo-ridaRegistered User regular
    GnomeTank wrote: »
    I'm not even sure what node.js is, but if I have gleaned correct information from the context...why on earth would you want to write anything complex and computation heavy like a MOBA backend in JavaScript?

    I mean, it looks like it's really just a model...couldn't you make it gobs more efficient with C++, or even a JIT'ed language like C#? Following the same basic model I mean.

    Javascript running in Node.js is, as far as I've read, effectively JIT'ed into C++ code

    That's what V8 is all about

  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited February 2012
    Recursion is beautiful, like how math can be sometimes, and anything that can be solved iteratively can also be solved recursively (and vice versa), but iterative code is almost always at least a bit faster than recursive code. You can fake the performance of iteration with tail recursion though. That being said, 95% of the time, if something would be more elegant with recursion, its worth a bit of performance.

    edit: Zeeny, after reading half through the first chapter I picked that book up and, yes, this is good stuff. It makes javascript's weirdness make a bit more sense.

    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
  • seabassseabass Doctor MassachusettsRegistered User regular
    edited February 2012
    Recursion is beautiful, like how math can be sometimes, and anything that can be solved iteratively can also be solved recursively (and vice versa), but iterative code is almost always at least a bit faster than recursive code. You can fake the performance of iteration with tail recursion though. That being said, 95% of the time, if something would be more elegant with recursion, its worth a bit of performance.

    edit: Zeeny, after reading half through the first chapter I picked that book up and, yes, this is good stuff. It makes javascript's weirdness make a bit more sense.

    Depends on the language. For example, in OCaml I often recur over a set of jobs, consuming them until empty. While I could do this with a while loop, doing it with a recursive call lets me use a list instead of a list reference. Mutable data structures are costly, so the recursive approach has a slight edge in that case.

    seabass on
    Run you pigeons, it's Robert Frost!
  • centraldogmacentraldogma Registered User regular
    figure here would be a good place to ask

    need to brush up on algorithms / be able to write some basic pseudocode for an interview

    won't need to know in depth technical stuff as it's not a programming position, but technical knowledge is needed

    haven't looked at this stuff in a few years, since data structures... where is a good place / what is a good way to review

    Algorithms by S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani is the book I used in college and the entire book is online for free at http://www.cs.berkeley.edu/~vazirani/algorithms.html.
    Recursion is beautiful, like how math can be sometimes, and anything that can be solved iteratively can also be solved recursively (and vice versa), but iterative code is almost always at least a bit faster than recursive code. You can fake the performance of iteration with tail recursion though. That being said, 95% of the time, if something would be more elegant with recursion, its worth a bit of performance.

    edit: Zeeny, after reading half through the first chapter I picked that book up and, yes, this is good stuff. It makes javascript's weirdness make a bit more sense.

    I was on an interview with a company that absolutely hated recursion because it's stack intensive. I think they used fibonacci as an example.




    signaturecreation.gif
  • jackaljackal Registered User regular
    That would make me nerd rage so hard. Fibonacci isn't a bad idea because it is hard on stack space (in fact it is linear on stack space). It is bad because it has exponential run time.

  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited February 2012
    The nieve fibonnaci and factorial recursion are sort of the poster children of why memoization is a good thing. (to be fair, I only remember that term because I'm reading this js book).

    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
  • EtheaEthea Registered User regular
    Jasconius wrote: »
    GnomeTank wrote: »
    I'm not even sure what node.js is, but if I have gleaned correct information from the context...why on earth would you want to write anything complex and computation heavy like a MOBA backend in JavaScript?

    I mean, it looks like it's really just a model...couldn't you make it gobs more efficient with C++, or even a JIT'ed language like C#? Following the same basic model I mean.

    Javascript running in Node.js is, as far as I've read, effectively JIT'ed into C++ code

    That's what V8 is all about

    The benchmarks I have seen place v8 performance behind pure C++. The issue is how to benchmark a compiled a language to one that does run time optimizations. I expect v8 performance to be really good on heavy branching code that has runtime branch trends.

  • JasconiusJasconius sword criminal Flo-ridaRegistered User regular
    edited February 2012
    It's OK if V8 is behind C++

    It doesn't have to be amazing. It just has to be better than average.

    IMO the computational exhaustion of enforcing game rules for a MOBA game are NOT the problem

    The problem is writing javascript on the client that will ferry that data back and forth to the server in a responsible way.

    WebSockets is a great tool but it certainly doesn't write the net code for you.

    It will demand a brutal crash course in client side prediction

    Jasconius on
  • EtheaEthea Registered User regular
    Removal of hit scan weapons will help.

  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Speaking of memoization and javascript, I wrote a node.js program that counts the number of prime factors of a number (duplicates included). This calculation is the core part that ulam spiral genearator I wrote last year in Go.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • seabassseabass Doctor MassachusettsRegistered User regular
    jackal wrote: »
    That would make me nerd rage so hard. Fibonacci isn't a bad idea because it is hard on stack space (in fact it is linear on stack space). It is bad because it has exponential run time.

    Just remember, there is a constant-time approximation of Fibonacci. I hate the example of Fibonacci as a dynamic programming problem, so I memorized the closed form approximation of the function just for interviews.

    Run you pigeons, it's Robert Frost!
  • SeolSeol Registered User regular
    edited February 2012
    seabass wrote: »
    Just remember, there is a constant-time approximation of Fibonacci. I hate the example of Fibonacci as a dynamic programming problem, so I memorized the closed form approximation of the function just for interviews.
    Questions and discussions about Fibonacci are, invariably, not about Fibonacci. Learning closed form approximations is a waste of time. Worse than, in fact, because by giving a sophisticated answer, you're almost certainly missing the point.

    Fibonacci is the standard question the interviewer asks where I work, and he laments that nobody, ever, has given what he considers the "right" answer. Which is "well, first I'd write a test". Tests supporting naive recursive Fibonacci are arguably better in the real world than clever closed form approximations - at least then you have a solid base to optimize on, and are only likely to do so when the need becomes apparent.

    But because everyone knows Fibonacci so well as an example, they start reeling off how to program it: the question shifts their brain into "Fibonacci mode" instead of "software development" mode. If the question was "How would you program <function you've never seen before>", you'd likely get a much more methodical answer.

    Outside of an interview context, is there an application for fast, high-value, accurate Fibonacci numbers? Or is it, as I suspect, just an example?

    Seol on
  • seabassseabass Doctor MassachusettsRegistered User regular
    Seol wrote: »
    seabass wrote: »
    Just remember, there is a constant-time approximation of Fibonacci. I hate the example of Fibonacci as a dynamic programming problem, so I memorized the closed form approximation of the function just for interviews.
    Questions and discussions about Fibonacci are, invariably, not about Fibonacci. Learning closed form approximations is a waste of time. Worse than, in fact, because by giving a sophisticated answer, you're almost certainly missing the point.

    Fibonacci is the standard question the interviewer asks where I work, and he laments that nobody, ever, has given what he considers the "right" answer. Which is "well, first I'd write a test". Tests supporting naive recursive Fibonacci are arguably better in the real world than clever closed form approximations - at least then you have a solid base to optimize on, and are only likely to do so when the need becomes apparent.

    But because everyone knows Fibonacci so well as an example, they start reeling off how to program it: the question shifts their brain into "Fibonacci mode" instead of "software development" mode. If the question was "How would you program <function you've never seen before>", you'd likely get a much more methodical answer.

    Memorizing the closed form approximation is certainly a waste. Even knowing how to derive it is sort of a waste. I just like to have a glib answer to that particular question.

    I always thought the best answer to such questions was to say something like, well, it's a dynamic programming problem, so you fill out a table containing answers to the smaller problems, working your way up to the problem you wanted to solve. Generally, any problem which has independent subproblems can be solved this way.

    "First I'd write a test" seems like an odd answer to a programming question. You might as well expect someone to say "First I'd open up a buffer" or "First I'd jot down the problem definition on a piece of paper" or "I'd start by turning on the PC". It's so fundamental to the process that it seems like it doesn't need saying.

    Run you pigeons, it's Robert Frost!
  • SeolSeol Registered User regular
    edited February 2012
    seabass wrote: »
    "First I'd write a test" seems like an odd answer to a programming question. You might as well expect someone to say "First I'd open up a buffer" or "First I'd jot down the problem definition on a piece of paper" or "I'd start by turning on the PC". It's so fundamental to the process that it seems like it doesn't need saying.
    Well, it's not a free-form talk about how you'd solve it, it's give you a piece of paper and ask you to implement Fibonacci - and nobody ever writes a test, it's always just the implementation.

    And you might say it's so fundamental to the process that is shouldn't need saying - for a lot of people, that's not true.

    Seol on
  • zeenyzeeny Registered User regular
    Lol. "First I'd write a test". Thank fuck I don't do interviews. :D

  • InfidelInfidel Heretic Registered User regular
    He never gets the "right" answer because his expectations are stupid.

    How would you perform an interview?

    Well first I would take a breath...

    TwitchTV channel: OrokosPA OrokosPA
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
  • EndEnd Registered User regular
    edited February 2012
    and then another breath, this one a deep one

    End on
    maybe nothing else is real
    zaleiria-by-lexxy-sig~medium.jpgsteam~tinythumb.png
  • ecco the dolphinecco the dolphin Registered User regular
    edited February 2012
    Then I'd double check to make sure that I was wearing trousers.

    You see, by taking the deep breath before the check, I am now able to handle the situation where I am not wearing suitable work attire by just sprinting out of the office and into my car. Without the deep breath, I would be unable to do this as efficiently.

    I think this shows that I am capable of forward planning, and also shows respect for the workplace.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • jackaljackal Registered User regular
    Knowing how to derive fibonacci just means you know college level linear algebra.

    Is fibonacci even a good question? Maybe it tells a lot about the programmer.
    Recursion: Warning. Just graduated college.
    Memoized Recursion: Warning. Functional Programmer.
    Iterative: Warning. Either very experienced or completely inexperienced.
    Precomputed Lookup Table: Warning. Watch your back. This guy is sneaky.

This discussion has been closed.