Fonzie's Tips on Getting started with programming

Everything related to programming.
Mgalekgolo
Commando
Posts: 2589
Joined: Thu Jun 24, 2010 6:36 am

Re: Fonzie's Tips on Getting started with programming

Post by Mgalekgolo » Mon Nov 14, 2011 9:57 pm

Holy shit, bugdom and nanosaur!
Yarok wrote:There may be a giant dildo protruding from your forehead.
Image

Sparky
Delta Force
Posts: 4194
Joined: Wed Mar 31, 2004 8:59 pm
Location: New Jersey, USA
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by Sparky » Tue Nov 15, 2011 1:17 am

"Bondi Blue" iMac software licensing of Pangea Software titles revealed!

Now known as Nostal-gea Software (eh?)!
Either you are groping for answers, or you are asking God and listening to Jesus.

nil
Halo Moderator
Halo Moderator
Posts: 1090
Joined: Sat Jul 05, 2008 8:38 am
Location: null zone

Re: Fonzie's Tips on Getting started with programming

Post by nil » Tue Nov 15, 2011 6:56 am

Fonzie wrote:meh, after you said something i went and changed mine up.

http://i39.tinypic.com/sq0bah.jpg

Its sexy.
Ruby:

Code: Select all

puts "Enter 5 numbers and I'll calculate the sum:"
sum = 0
5.times do
    sum += gets.to_i
end
puts "The sum is #{sum}"
[EDIT]:
Even more fun way:

Code: Select all

puts "Enter 5 numbers and I'll calculate the sum:"
puts "The sum is #{Array.new(5){gets.to_i}.inject(:+)}"
Note your C++ example is kind of odd. It is more conventional to have x start at 0, and test for while (x < 5). "total = total + number " is equivalent to "total += number", you ought to be really using a for loop instead of a while loop - what you really want is to iterate something 5 times, you don't actually care what x is through every iteration, yet it is being kept around visible to you. The first Ruby solution I present solves this issue elegantly using blocks - no worries about bounds.
I am no longer active to Halo or MGM, and don't guarantee a response on the forums or through email. I will however linger around the discord room for general chatting. It's been fun!

draconic74
Green Beret
Posts: 3470
Joined: Sat Jun 03, 2006 11:08 am
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by draconic74 » Tue Nov 15, 2011 10:27 am

Nitpicky, but true.

Also, HOLY HELL BUGDOM. When I used to have an old HPP desktop oh so many years ago, before I knew of this community, my dad would occasionally bring home one of the fruity-colored iMacs from the university. I remember I had to go behind the couch in that house, because that was the only place that had both an outlet and an internet cable (why, I don't know. I was young back then, I couldn't care). I would sit there for hours playing Bugdom, Nanosaur, and flash games on CartoonNetwork.com. Because apparently my HP didn't have flash, or was too slow to run them, or something. I just remember I never played those games on the HP, and now I can't remember why. I could never get far in Nanosaur, but luckily Bugdom was a bit easier. I think I actually managed to beat the game. There was also Cro-Mag Rally, but that wasn't nearly as fun as the other two.

Oh look, more musical nostalgia. If you ever played Bugdom for even a bit, you should remember this. As soon as I started hearing it, memories... Oh my.


I also remember playing MDK on his insanely old laptop. Anyone remember that one? That was a goddamn hard game. And even further back... In fact, you know, I think the first game I might have ever played was Asteroids. It was on one of these:
Image

That thing is still sitting on a shelf back at home. We still have the charger too. Shame it doesn't work.
Image

Fonzeh
Ranger
Posts: 1894
Joined: Tue Oct 16, 2007 3:57 am
Location: "I didn't just take your mom out to dinner. I ate your mom for dinner."
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by Fonzeh » Tue Nov 15, 2011 1:27 pm

Ah yes, I did change it to 0 later, noticing it was off, this picture was taken beforehand.
Also I counter with this.

Image
G[v]N wrote:HUGE NOTIFICATION
THIS GRAVY HAS BRAINS
Mota-Lev was here 30/4/2010@2:18pm
Image

Amy
Green Beret
Posts: 3628
Joined: Mon Nov 17, 2008 6:22 pm
Location: Mota-Lev's house.
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by Amy » Tue Nov 15, 2011 2:16 pm

TaxiService wrote:
http://www.angelfire.com/nj/peanutbutter/pbj.html wrote:The song which should be playing is entitled "Night". It is taken from Bugdom (a game by Pangea Software).
HOLY SHIT DUDE

HOLY SHIT

MY CHILDHOOD
WTF TAXI WHY HAVEN'T YOU SPOKEN TO ME ABOUT THIS. I KNEW THE CEO OF PANGEA, HE GOT ME INTO GAMING.
MGM Sig
Mota-Lev wrote:Its like watching an Asian girl crush a cats brain through its eye socket with high heels.. Its horrible but I just can't look away :/.

draconic74
Green Beret
Posts: 3470
Joined: Sat Jun 03, 2006 11:08 am
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by draconic74 » Tue Nov 15, 2011 2:38 pm

Code: Select all

with Ada.Text_IO;
use Ada.Text_IO;

procedure age_thing is
    ageTotal, age, derp : integer := 0;
begin
    put("I heard you like ages, so Imma put ages inside of ages just for you. Or -7 to quit, whatevs.");

    loop
        get(age);
        exit when age = -7;               -- I love this command, btw. but thats the only one so far that I like in Ada
        ageTotal := ageTotal + age;       -- Ada doesnt have +=, :sad face:
        derp := derp + 1;                 -- No ++ either! ARGH!
    end loop;

    put("Number of ages aged into ages: ");
    put(derp);
    New_Line;
    put("Average age: ");
    put(ageTotal/derp);
    -- Yeah, without some more advanced command things you can't put variables
    -- and strings into the same line. Herp derp. Also, no quote blocks, like C++'s   /* Helloes */

end age_thing;
Oh damn, multiple spacing works in code blocks. Hell yeah!
Image

Sparky
Delta Force
Posts: 4194
Joined: Wed Mar 31, 2004 8:59 pm
Location: New Jersey, USA
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by Sparky » Tue Nov 15, 2011 3:16 pm

Procedural programming is fun for simple things.

Draconic, MDK was really fun, but for some reason kept crashing on me, if I recall correctly.
Either you are groping for answers, or you are asking God and listening to Jesus.

nil
Halo Moderator
Halo Moderator
Posts: 1090
Joined: Sat Jul 05, 2008 8:38 am
Location: null zone

Re: Fonzie's Tips on Getting started with programming

Post by nil » Tue Nov 15, 2011 6:22 pm

My approach:

Code: Select all

def get_ages
    age = gets.to_i
    return (age == -1) ? [] : ([age] + get_ages)
end

puts "Enter ages for people. Type -1 to stop."
ages = get_ages()
puts "Number of people entered: #{ages.count}"
exit if ages.count == 0 #Forgot to avoid divide by zero, edited this later in - so, there is no average age if this is the case
puts "Average age: #{ages.inject(:+) / ages.count}"
Nitpicking is important, especially when there is code that could be improved upon. I'll nitpick's Fonzie's code above soon when I get the chance.
Last edited by nil on Thu Nov 17, 2011 10:33 am, edited 2 times in total.
I am no longer active to Halo or MGM, and don't guarantee a response on the forums or through email. I will however linger around the discord room for general chatting. It's been fun!

Sparky
Delta Force
Posts: 4194
Joined: Wed Mar 31, 2004 8:59 pm
Location: New Jersey, USA
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by Sparky » Tue Nov 15, 2011 7:41 pm

nil, please give reasons why you prefer ruby over other languages.
Either you are groping for answers, or you are asking God and listening to Jesus.

Mgalekgolo
Commando
Posts: 2589
Joined: Thu Jun 24, 2010 6:36 am

Re: Fonzie's Tips on Getting started with programming

Post by Mgalekgolo » Tue Nov 15, 2011 8:07 pm

Ruby is awesome.
Yarok wrote:There may be a giant dildo protruding from your forehead.
Image

draconic74
Green Beret
Posts: 3470
Joined: Sat Jun 03, 2006 11:08 am
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by draconic74 » Wed Nov 16, 2011 12:59 pm

Diamond was better. As was Silver.

Also, yes, nitpicking is a good thing. But try not to use too much of the advanced stuff if you do so. We are not at your level yet. The idea of using '+=' and starting at 0 is good, but in code this simple the idea of using 'for' or 'while' is debatable. To me, anyway. In more advanced code there is a definite reason to use one or the other, but I don't really see a reason to use one or the other in this one. Also, someone's choice language is simply that, their choice. They have reasons they like it better than other languages.



Fun fact:

Code: Select all

,.
In a certain language, this code will output a single character you input. Anything more complicated then that I will not try to mess with quite yet.
Image

Fonzeh
Ranger
Posts: 1894
Joined: Tue Oct 16, 2007 3:57 am
Location: "I didn't just take your mom out to dinner. I ate your mom for dinner."
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by Fonzeh » Wed Nov 16, 2011 1:47 pm

^ Agreed, any modifications you nitpick must be explained so we know why you did it, and why it's more efficient, that way, we all learn!
G[v]N wrote:HUGE NOTIFICATION
THIS GRAVY HAS BRAINS
Mota-Lev was here 30/4/2010@2:18pm
Image

draconic74
Green Beret
Posts: 3470
Joined: Sat Jun 03, 2006 11:08 am
Contact:

Re: Fonzie's Tips on Getting started with programming

Post by draconic74 » Wed Nov 16, 2011 2:03 pm

Well, I can explain += and starting at zero.

Code: Select all

variable1 += variable2;
variable1 = variable1 + variable2;
These two lines are essentially the same. Instead of using '=', you can use '+='. It's meaning is simply "This variable is equal to itself plus whatever comes after the '+=. "

For starting at zero, well... It's just a computer thing. Everything starts at zero. When you start using arrays, in C++ they start at zero (in other languages you can define their range). It's just a consistency thing.
Image

nil
Halo Moderator
Halo Moderator
Posts: 1090
Joined: Sat Jul 05, 2008 8:38 am
Location: null zone

Re: Fonzie's Tips on Getting started with programming

Post by nil » Wed Nov 16, 2011 8:05 pm

draconic74 wrote:Also, yes, nitpicking is a good thing. But try not to use too much of the advanced stuff if you do so. We are not at your level yet. The idea of using '+=' and starting at 0 is good, but in code this simple the idea of using 'for' or 'while' is debatable. To me, anyway. In more advanced code there is a definite reason to use one or the other, but I don't really see a reason to use one or the other in this one. Also, someone's choice language is simply that, their choice. They have reasons they like it better than other languages.
I can point out issues in code while understanding that one is not using the more *different* approaches like I am. Exposure to different approaches and ways of programming is a good thing as well as exposure to different programming languages. One can choose to start with any programming language, but he should not limit himself to one. Just because one uses a particular language does not convince me that he actually likes it better than others, which is often the case when one does not have enough experience to make a proper judgement.

+= is a shorthand like you explained, the benefit is obvious: less typing and code. I mentioned this before, though. I also explained starting at 0 as being a convention like you mention. I guess this is kind of a debatable point but many languages like starting at 0 and it often makes sense when accessing indexes or referencing memory and doing arithmetic on them.

I personally think for loops should be used in cases like:

Code: Select all

for (int index = 0; index < 5; index++)
{
    //...
}
As opposed to:

Code: Select all

int index = 0;
while (index < 5)
{
    //...
    index++;
}
..where the while loop is merely simulating the for loop.

In Fonzie's particular case, he just wants to repeat doing something 5 times - the counter is not actually important. Ruby offers a nice way of iteration for this scenario using closures as I showed above.
I am no longer active to Halo or MGM, and don't guarantee a response on the forums or through email. I will however linger around the discord room for general chatting. It's been fun!

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests