Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 15 May 2010
Offline Last Active Yesterday, 01:07 PM

Posts I've Made

In Topic: 99 bottles Challenge thread 2

11 July 2015 - 09:40 AM

My first attempt was in Python with 254 characters:

for i in range(99,-1,-1):
    s=lambda k,n: (n+"o more"if k<1 else str(k))+" "+(a+""if k==1 else a+"s")
    o="of beer"
    e=o+" on the wall"
    print s(i,"N"),e+",",s(i,"n"),o+".\n"+("Take one down and pass it around, "+s(i-1,"n")if i>0 else "Go to the store and get some more, "+s(99,"")),e+".\n"

It's alright. I like how the lambda helped wrap some of the switching into one (kind of) concise function, but I kind of wish it used less characters. I also wish Python had a ? operator. Damn you Python for trying to be expressive!

I thought then I'd have a hand at the challenge in a functional language. Enter Haskell:

a=" bottle"
y="o more"
b 0="n"++y++e
b 1="1"++a
b n=show n++e
c=" of beer"
d=c++" on the wall"
q n=z[d,", ",b n,c,p]
f 0=z["N",y,e,q 0,"Go to the store and buy some more, ",b 99,d,p]
f n=z[b n,q n,"Take one down and pass it around, ",b $ n-1,d,p,"\n",f(n-1)]
main = putStrLn(f 99)

with 253 non-ws characters. I suck at Haskell biggrin.png It too me forever just to set up the main function.


I started writing another version in Java but I reached 200 characters just setting up a bare bones program. I'd probably go well into the 300s with it.

EDIT: I actually think I might have stolen that Haskell version from someone on the old thread a while ago and not realized it. My version uses less characters though :D

In Topic: how to program A LOT of skills/spells?

28 June 2015 - 07:56 AM

You could employ a Prototype pattern: http://gameprogrammingpatterns.com/prototype.html

If you have a lot of if/else statements or a large switch, you should probably start thinking about how to alleviate all those checks. 


In addition, if you haven't read through some of those design patterns, I suggest you do. They're pretty awesome and they can make your code a lot more flexible.

In Topic: Spot the bug quiz.

14 May 2015 - 09:39 AM


Writing code in C++ does not automatically mean the coder is even aware of what cache coherency is.

That isn't my point. You are correct that learning C or C++ does not magically make you aware of how to optimise cache usage.


But the sad truth is that learning Java pretty much guarantees that you will not be aware, as the language doesn't have the necessary mechanisms to do anything about it.


Oh yeah, I'm aware, that's why I removed the quote as it wasn't really on-point.

In Topic: Spot the bug quiz.

13 May 2015 - 10:00 AM

Writing code in C++ does not automatically mean the coder is even aware of what cache coherency is. If the intent is to teach people about making effective use of CPU cache, then it is imperative to teach people about the effective use of CPU cache. Throwing them into a pit with a low level language doesn't accomplish anything and can arguably make things worse (just check out that Lugaru code I linked to in the first post. Written entirely in C++ I believe).


A lot of people naively think that absorbing the contents of a CS degree makes them a decent programmer. As far as I'm concerned, coming out of school with that mindset the student does a great disservice to himself. At my university, the CS students start with Intro to C and move on to Comp Sci which is taught in C++. None of those classes ever mentioned cache, or the inner workings of virtual functions. 


Of course, if you're using a high level language like Python, it's rather unlikely that you'll hear anything about any of those concepts, whereas with C++ you might at least come across it one day. 


Then again, I don't even know how to write a Makefile, let alone an efficient one biggrin.png


EDIT: Removed quote. I don't think it was necessary.

In Topic: Spot the bug quiz.

11 May 2015 - 09:35 PM



Then again I advocate learning with something like C or Pascal variants, and only then moving onto managed or scripting languages. Exclusively learning and using managed languages seems like a bad idea to me.


I myself started with C++ I think. It was alright, but knowing what I know now, I don't know if today I wouldn't start with Python first. I don't even like the language, but at my internship Python is the main flavor of the proverbial kool aid. Personally, I find it annoying, but it might be more so because I've been using Java for the vast majority of my programming career. It is by no means a bad language. I'm simply not proficient in it.