Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jywv8

macrumors 6502
Jan 11, 2003
322
0
Chicago
I've been a programmer for 8 years. I always recommend that people start learning programming with C. I started out with Pascal, then moved on the C, then Java, then C++, and I picked up Perl, PHP, and Python along the way. For me, I think starting out with C++ would have been overwhelming, and Java doesn't teach you basic memory management fundamentals.

cubist said:
Programming calls for two skills IMO, visualization and memory. Visualization means to be able to picture in your mind an abstract thing which is doing things, the program or module. Memory simply means being able to remember thousands of nitnoidal facts - managing complexity, in other words.

I completely agree about visualization and managing complexity. I find it very difficult on work on a system when I don't have a general "map" of it in my head. To this list of skills, I would also add "patience" and "attention to detail". On a bad day, programming is a PITA. On a good day, it's like doing a puzzle. I like puzzles.

I agree with jsw:

jsw said:
Ultimately, I think almost anyone can program, especially if they are taught, at least initially, by someone good - just like anyone can learn to talk. But some people are just better at it than others.
 

Mav451

macrumors 68000
Jul 1, 2003
1,657
1
Maryland
devman said:
...
There does seem to be a correlation between musical talent and programming FWIW. I've not ever heard of the language correlation before.
...

I wish man. 8 years of piano, and 6 years of percussion/drums. 5 years of all-county/all-state band.

...Didn't help one bit in my programming -_-.

And explaining something? I've taught a ton of people on how to build PCs, and my writing is pretty decent (A's in both Freshmen and Junior English, the latter being Technical Writing). If you doubt my writing skills, I can send you some of my material (the latest being an overclocking guide for Technical Writing).
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,782
7,514
Los Angeles
Another thing to consider is that almost anybody can be forced at gunpoint (or, more appropriately, gradepoint) into getting through a programming class, but your personality may determine whether you like doing this sort of activity.

Thinking logically (considering all cases and what could go wrong) and writing algorithms for what is a rather stupid beast (it follows directions instead of using any common sense) is normal for Vulcans and certain other species. Other people consider such work tedious. It's not talent, it's interest.

If you consider every program to be a fun coding challenge, so be it. If you consider it a chore, so be it

Sometimes it helps to "think like the computer" when programming and this comes more naturally to some people than others. A primitive example:

Suppose the computer sees "10,240" and complains that you typed a list of numbers when it wanted a single number. If you think about how it parses text, realize that it thought the comma was a list separator, laugh, consider it YOUR error, and try not to do it again, you're handling the problem like a programmer.

If, instead, you say "stupid computer", type "10,240" again, see it fail again, and then throw the whole machine out the window, you may not have the right personality for this particular profession or hobby.

And if you rewrite the parser on the spot so it handles commas differently, things are looking really good for you!
 

notjustjay

macrumors 603
Sep 19, 2003
6,056
167
Canada, eh?
Wow, neat thread, lots of cool input and advice.

I would second the notion of learning a simpler, procedural language first. I started off programming in the 80's with Applesoft BASIC on the good ol' Apple ][. I learned a lot through trial and error and from typing in program listings from magazines like Nybble and Compute! (oh man was I ever a nerd ;) ). From there I went into Microsoft QuickBASIC for DOS (at least, the dumbed-down QBasic interpreter that they included with every version of DOS past 5.0), then in high school I learned Basic and Pascal on the Mac. I was also teaching myself C at home, and in university we did C++ and Java. I've since also picked up PHP.

I actually would NOT recommend PHP as a starter language because its paradigm is so different and since it doesn't really do you much good outside of a web server.

I can see why learning C++ or Java might be hard for a complete beginner, I mean look at what you have to do for a simple "Hello World" program:

public class HelloWorld {
public static void main() {
System.out.println("Hello world\n");
}
}

When all I ever did in BASIC was:

10 PRINT "HELLO WORLD"

:)

(then of course, you add 20 GOTO 10 :D )
 

5300cs

macrumors 68000
Original poster
Nov 24, 2002
1,862
0
japan
Wow :eek: So much advice from everyone. Thanks!!

I had thought that trying to tackle a difficult language first would be difficult, but then I remember reading in a book that if you learned C first, you'd have to un-learn things to start with Java :( So I thought that if I started with BASIC or something, then I'd be wasting my time because a.) it's a dead language (maybe) b.)it uses a different syntax and c.)doesn't help me in the future.

I'm envious when I hear people talking about how they used to program games in their spare time when they were young, like dice rollers and dungeon exploration games, etc. I wish I could do the same.

Also programming might be something that I could put on my resume if I ever became proficient enough to do something useful with it, or ended up making something useful. For example, I wanted to make my own text editor, or AIM client.

Thanks again for all the advice and keep it coming! :D
 

broken_keyboard

macrumors 65816
Apr 19, 2004
1,144
0
Secret Moon base
I started programming when I was 8, going in to school early in the morning to use their computer. I am now 30 and have been a professional programmer all my life.

I just want to say that I sympathize with people starting programming today. The languages I started with were much more designed for the hobbiest, but today's languages (such as Java) are often designed with business in mind. These days people have to be a lot better at separating out the essential from the non-essential, because there is a lot more of the inessential.
 

applekid

macrumors 68020
Jul 3, 2003
2,097
0
As long as it's not too late to throw in my comments...

I think that article Doctor Q is pointing out is right.

I learned BASIC when I was 10. I came across my dad's old FutureBASIC books, and since I still had the floppies, I installed it on our Quadra 650. My dad quit learning to programming for some reason. I don't know why he picked it up in the first place either. He has tons of old C programming books on his bookshelf, but it seems like it was all a wasted effort.

Anyhow, I programmed a few simple text-based programs and was excited. So, I wrote some stupid text-based games and demos for fun. The FutureBASIC package came with a very thin book of examples and problems for you to solve. Through those examples, I learned simple things in BASIC.

Anyways, I struggled figuring out BASIC on my own. I wasn't able to move forward from those simple text-based programs. I aimed to make simple games (my goal was to make a Donkey Kong-clone. On the Mac, I have never seen a good Donkey Kong clone!), but I couldn't get graphics to draw or anything. So, I took a hiatus.

Come back to age 14, in high school, taking Computer Science 2 in my freshman year. I skipped CS1 because I was able to prove my computer skills. Anyways, my teacher... Well, he knows his stuff, but does not teach it to us. Our CS2 class was all about Java, when the county's curriculum was for C++. He wanted to teach us Java because it was new and the AP exams were going to be based on Java. He didn't know a lick of Java and was teaching himself at the same time. That did not help our cause because we were the guinea pigs.

Our first Java programs were all done in one class and in the main. What a breeze. It was like going back to the BASIC days... Then, we somehow jumped into OOP. He demanded we split up our programs into two classes. He didn't even tell us how! So, for a week, we struggled with a particular program. Then, he went over some code with us to work with since we had so much trouble (except for one kid, more on him later). He sorta explained the concept of OOP and all that jazz. Still didn't make sense to us.

I took the code home, read over it, and tried to figure it out. I did this for two weeks. A few kids managed to figure out how to do program, luckily. But, for the majority of the class, we didn't know sh*t still. So, came the midterm, I got a C. Two B's for the quarters so I was guaranteed a B for the year. I went back to my code. It still didn't make sense. Then, it finally hit me. All of the class declarations were like declaring variables. You type the class's name, a name for what I think of as a variable, equals, new, class name(). Of course, I later learned about parameters. But anyways, I taught myself that much. I figure out methods easily right after that. I finally had a basic understanding of Java.

After that, I got A's for the next two quarters, I taught my peers, we worked together, and figured out our programs. Programming became a cinch. We figured out we had to demand our teacher to sit with us and keep him still, in order to get help with our programs.

The next year, I took CS3. Aced that class. Most of my classmates from last year failed to join me. Only, I think 6 kids from my class joined me. The rest of the CS3 class was from a different CS2 class that actually learned C++, and learned OOP, and understood programming. Anyhow, I was near the top of my class in CS3. Programming was so easy because it seems like our CS2 class was based on a curriculum for the CS3 AP class. So, when the AP exam came, we were extra prepared. I got a 4. It's good, but most of my class got a 5 (we have so many over-achievers).

I moved up to my current CS4 class. Many more people dropped out of CS. But, now, for some reason, our teacher is a complete jerk. He used to be quite lenient with programs, but now he has really short due dates and makes us do ridiculously hard programs. It's like CS2 all over again. And my grades show it. He's moving to a new school next year, so some of us assume he's disgruntled. He does do more in-class teaching, but he's making us way too prepared for the Computer Science AB exam. And it's just become stressful again.

Oh, that kid I was talking about earlier. Well, he knew his stuff with computers. But, that first day we learned Java, he didn't know how to even type one line of code. We had our simple programs up and running, but this kid did and knew nothing! The screen was blank. I assume he got help from our teacher and learned Java during one afternoon. The next year he was in CS4, not CS3! It doesn't make sense...

Anyways, in summary, it helps to have a teacher that knows what they're doing. I found all books to be useless. I tried teaching myself C++ between my education of BASIC and Java, but books weren't the same as someone teaching you. Even if my teacher wasn't very good, he taught a few simple things that made quite a difference. It also helps to have friends learn with you. In CS2, I had only one friend in that class, but he was just a failure and ended up dropping out. CS3, everybody in the class was my friend. And CS4, I only have three friends with me. It relieves some stress when you code with friends. For Java in particular, java.sun.com is all you need. The forum often has useful examples and the API defines everything you need.

So, I suppose certain people are cut out to be programmers. But, let me say I'm either pursuing something I really shouldn't be (seeing my many failures), or I'm the low-end as far as programmers go (again, seeing my many failures).

Mav451, I'm a little disappointed that University of Maryland (College Park, I assume?) sounds like it doesn't have a good Computer Science department. My teacher always raves about them and things.
 

virus1

macrumors 65816
Jun 24, 2004
1,191
0
LOST
maybe this is the right place to ask for help. I figure the best dev environment for the mac is obj c because it is oo and it gets cocoa. (so does java but i chose obj c.. sue me) so i got the basics down kinda. im loose, but i understood it. now as soon as i got into cocoa and trying to understand the classes that make things work, i hit the wall. i feel like i took one step forward and 2 back because now im wondering if i got the basics right because this stuff is so confusing.. i wonder if i am in the category that everybody else here is in.. ive been struggling with this for a while.. i figure i better learn now or never cuz my little brains still developing.. 13 yo(thats 13 years old.. not 13 yo! i don't try to be 'from da hood').. HELP ME OUT
 

Omen88

macrumors regular
Jan 8, 2002
177
0
Flanders (Belgium)
virus1 said:
maybe this is the right place to ask for help. I figure the best dev environment for the mac is obj c because it is oo and it gets cocoa. (so does java but i chose obj c.. sue me) so i got the basics down kinda. im loose, but i understood it. now as soon as i got into cocoa and trying to understand the classes that make things work, i hit the wall. i feel like i took one step forward and 2 back because now im wondering if i got the basics right because this stuff is so confusing.. i wonder if i am in the category that everybody else here is in.. ive been struggling with this for a while.. i figure i better learn now or never cuz my little brains still developing.. 13 yo(thats 13 years old.. not 13 yo! i don't try to be 'from da hood').. HELP ME OUT

I recognize my childhood dreams I had at your age :) But back at that time programming was easier to learn in my opinion. I have learned a lot of languages and frameworks, and I must say Objective-C with Cocoa has a really steep learning curve (the steepest I have ever came across).

I'm 23 now, doing my 3rd year Master of Computer Science (I first did a prof bachelor CS). And I still find Objective-C pretty hard. Once you get it, you'll never want to do it in any other way. But boy it can be hard to get it.

Now I don't want to demotivate you. 13 is a great age to learn programming (you still have lots of room in your head, and lots of free time :). Start with very simple applications, congratulate yourself when you succeed, because making any cocoa application at 13 is a great accomplishment. And if possible find someone who has experience in Cocoa, and get them to teach you. Although chances are small you'll find someone (I never got help when I was young).

I hope you don't give up and get the hang of it. And I'll be glad to help you out if you have problems with something (look at my profile for Instant messaging).
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,782
7,514
Los Angeles
Rather than feeling lost in a huge library and wondering how to use it, I think you'd be better off starting with existing programs for which you have source code and analyzing how they work. Then see if you can make a few tweaks to some of them. That's a lot easier than writing your own program from scratch.
 

virus1

macrumors 65816
Jun 24, 2004
1,191
0
LOST
Omen88 said:
I recognize my childhood dreams I had at your age :) But back at that time programming was easier to learn in my opinion. I have learned a lot of languages and frameworks, and I must say Objective-C with Cocoa has a really steep learning curve (the steepest I have ever came across).

I'm 23 now, doing my 3rd year Master of Computer Science (I first did a prof bachelor CS). And I still find Objective-C pretty hard. Once you get it, you'll never want to do it in any other way. But boy it can be hard to get it.

Now I don't want to demotivate you. 13 is a great age to learn programming (you still have lots of room in your head, and lots of free time :). Start with very simple applications, congratulate yourself when you succeed, because making any cocoa application at 13 is a great accomplishment. And if possible find someone who has experience in Cocoa, and get them to teach you. Although chances are small you'll find someone (I never got help when I was young).

I hope you don't give up and get the hang of it. And I'll be glad to help you out if you have problems with something (look at my profile for Instant messaging).
i already have sombody that is helping me. the only problems are that he is very busy, and lives in canada, so we can only communicate via email and aim. thanks for the support.
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,782
7,514
Los Angeles
virus1 said:
i already have sombody that is helping me. the only problems are that he is very busy, and lives in canada, so we can only communicate via email and aim. thanks for the support.
Somebody with experience sitting next to you is the ideal, but having people to help, even remotely, is handy too, as are tutorials and books. I've found Apple's developer tutorials to be pretty good.
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
I'm going to break my advice into two posts, so the different ideas can stand on their own.

First, the question of whether programming is for you:

- Do you look at the world around you with curiosity?
- Do you think about how every large thing is composed of smaller and smaller parts?
- Can you plan something out, methodically, step by step?
- Can you take each of those steps, that anyone would take for granted as being completely obvious, and break them up into even smaller steps, so that a complete and utter idiot (computer) could get it done?
- Can you take multiple competing criteria, and find a solution that meets all needs?
- Can you compromise?
- Would you be comfortable describing yourself as a professional problem solver?
- Can you think analytically, scientifically, and logically?
- Do you want to spend the rest of your life learning new things?
- Can you, given a good book or website, teach yourself?
- Do you want to create?
 

Mechcozmo

macrumors 603
Jul 17, 2004
5,215
2
I am a programmer. Kinda.

Learned C++ in Visual Studio 6.0 at a summer camp. Did that enough years that I was beating the counselors at programming. My crowing achievement: a program that counted to the number you set, and would allocate memory along the way. So enter "100" and thats how much memory it would take up. Make a big enough number and you could crash the computer. Forgot most of it however...

Took Computer Science in 9th grade. Was supposed to be Java (AP class) but so much of the class failed we fell back to Visual Studio.NET which isn't the most useful of languages. I've found that its easy to make code but I'm often frustrated at the lack of power and lack of ability to bring it to other places. Basically, it is Windows only.

Learning C++ (again) now. Going nicely in Xcode. I'm hoping to, by the end of the summer, be able to make C++ programs that may not be the best in the world but can do anything I want them to do.
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
How to learn to program, from my experiences:

Learn some simple Math. Junior High or Senior High level should suffice to begin.

Learn the Scientific Method. It directly relates to Computer Science. This should take less than an hour.

Learn binary, octal and hex. Be able to add, subtract, multiply in these bases, using paper and a pencil. This should take a day or two.

Learn the logical concepts of AND, OR, NOT, XOR, and how this applies to binary values. In short, learn boolean algebra. If you've learned set theory or formal logic then this should be a rehash. This should take a few more days.

Now that you understand the theory of how a computer represents its data, and what mathematical operations it can do to that data, you need to learn how that works in practice. That is, you have to learn how instructions and data are stored in RAM, and how the CPU accesses and executes them. This will be in my next posting.

Take a simple language like C or Pascal, and learn the following concepts:
- Data types
- How to print something out
- Variables
- Arrays
- Flow of control
- Looping
- Functions
- Structures
- More complex input and output (files)

Program with this model for at least two months, if not longer, before moving on to a language like Java to learn Object Oriented Programming. Focus on that paradigm, and explore making graphical programs for another two months.

Congradulations, you are ready to START to learn Computer Science.
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
Everyone will tell you to learn a high level language like Java first. They're wrong. The best approach is to start at the lowest level possible and work your way up.

Master one level, and then you will comprehend the abstractions and shortcuts of a higher level.

Plus, when something fails, sometimes you need to fallback to simpler levels, to know what's "really" happenning.

All very good programmers know how a computer works at a low level, even if they only program it at a higher level.

Many poor programmers do not understand the low level concepts, and so have no basis to understand the higher level ones.

Code:
We'll use a theoretical architecture as a model:

CPU
- Two registers R0, R1 which are referenced as 0 and 1
- Registers are 8 bits large (so you can do math on paper easily)
- Instructions are all 2 bytes or 16 bits large
- A CPU reads in an opcode, interprets it, and executes it
- CPUs only understand bits and bytes, nothing else.  When you think of letters and words and pixels and pictures, those are all just things that we can represent by numbers. And numbers are represented by bits and bytes.

Memory (RAM)
- 256 bytes of memory, at locations 0 to 255 inclusive
- A single location is 1 byte or 8 bits
- A location could hold one number that would fit in a register
- Two adjacent locations could hold an instruction, which the CPU could execute

Opcodes  Instructions
---------------------
0x0000        HALT  (this ends a program)
0x1raa        LOAD into register r from address aa
0x2raa        STORE from register r into address aa
0x03sd        ADD source register s into destination register d
0x04sd        SUB (subtract) source register s from destination register d
0x05sd        MUL (multiply) source register s into destination register d

0x30sd        AND source register s into destination register d
0x31sd        OR source register s into destination register d
0x32sd        XOR source register s into destination register d
0x330d        NOT destination register d
0x340d        CLR (clear) destination register d to zero

0x40sd        CMP (compare) source register s to destination register d
0x41aa        JL (jump if s < d) to address aa
0x42aa        JLE (jump if s <= d) to address aa
0x43aa        JE (jump if s == d) to address aa
0x44aa        JGE (jump if s >= d) to address aa
0x45aa        JG (jump if s > d) to address aa
0x46aa        JMP (unconditionally jump) to address aa

Assume that when starting up, the CPU starts by executing the instruction at address 0x00.

Let's make a sample program that takes two numbers from memory, adds them together, saves that to memory, and then halts.

Location  Instruction        Opcode
----------------------------------
0x00        LOAD R0, 40      0x1040
0x02        LOAD R1, 41      0x1141
0x04        ADD R1, R0        0x0310
0x06        STORE R0, 42    0x2042
0x08        HALT                0x0000

Location  Value
---------------
0x40        0x23
0x41        0x0F
0x42        0x32   <-- This value was filled in when running program

Test math on paper:
  0x23 => 2*16+3 = 35
  0x0f => 0*16+15 = 15
  35+15 = 50
  50 = 3*16+2 => 0x32

Now let's try an example with a condition.  In a higher level language we use IF and  ELSE IF  and  ELSE  so that we can conditionally execute code depending on some criteria.  With the ability to branch/jump/goto  based on the outcome of a conditional test, we can implement IF, ELSE IF, ELSE.

Real world example:  Movie tickets cost different amounts if sold to children, adults or seniors.

Higher level programming example:

IF age < 18
    cost = 5
ELSE IF age >= 65
    cost = 4
ELSE
    cost = 8

Lower level example:

The first thing we have to do, is realise that sort of 2 dimensional view of higher level languages, where they "nest" code simply does not exist from the CPU's perspective. To the CPU, everything is 1 dimensional and linear.  It just does one thing after the other.  So, we have to rearrange our code into a series of conditions and jumps (gotos).

Here's one way, which jumps based on the opposite test, but where everything's laid out in the same sequence as the higher level code:

IF age >= 18    GOTO AdultOrSenior
cost = 5
GOTO HaveCost
AdultOrSenior:
IF age < 65    GOTO Adult
cost = 4
GOTO HaveCost
Adult:
cost = 8
HaveCost:

Here's another way, which does the test the same as the higher level language, but where everything's laid out in the opposite sequence as the higher level code:

IF age < 18    GOTO Child
IF age >= 65    GOTO Senior
cost = 8
GOTO HaveCost
Child:
cost = 5
GOTO HaveCost
Senior:
cost = 4
HaveCost:


So we see that where something is straightforward and simple in a higher level language, there might be many complex ways of doing it in a lower level language.

Here's the second method reduced to a lower level:

Location  Instruction        Opcode
----------------------------------
0x00        LOAD R0, 0x40       0x1040    # IF age < 18    GOTO Child
0x02        LOAD R1, 0x41       0x1141
0x04        CMP R0, R1          0x4001   
0x06        JL 0x12             0x4112

0x08        LOAD R1, 0x42       0x1142    # IF age >= 65    GOTO Senior
0x0A        CMP R0, R1          0x4001   
0x0C        JGE 0x16            0x4416

0x0E        LOAD R1, 0x45       0x1145    # cost = 8

0x10        JMP 0x18            0x4618    # GOTO HaveCost

0x12        LOAD R1, 0x43       0x1143    # Child:  cost = 5

0x14        JMP 0x18            0x4618    # GOTO HaveCost

0x16        LOAD R1, 0x44       0x1144    # Senior:  cost = 4

0x18        STORE R1, 0x46      0x2146    # HaveCost:   (save away cost into RAM)
0x1A        HALT                0x0000

Location  Value
---------------
0x40        0x19   <-- age we'll pick 25.   25 = 1*16+9 => 0x19
0x41        0x12   <-- age of adult  18 = 1*16+2 => 0x12
0x42        0x41   <-- age of senior  65 = 4*16+1 => 0x41
0x43        0x05   <-- cost for a child
0x44        0x04   <-- cost for a senior
0x45        0x08   <-- cost for an adult
0x46        0x08   <-- cost that we calculate to charge


As an aside, a lot of higher level programmers don't know what pointers are, but low level programmers do.
In memory, we have locations, and what's actually at that location. Think of each location as a little bucket that can hold an actual value.
In the above example, location 0x46 holds the value 0x08. So, we could pass around the value 0x08, or we could pass around a pointer to it, which would be 0x46.

That is, I could tell you the cost of $8, or I could tell you where to go ( location 0x46 ) to get the cost. The pointer is 0x46.
 

Blackjack75

macrumors newbie
May 6, 2005
20
0
Starting with ASM

I agree with the previous post: it is very important to _know_ what happens behind when you use a high level programming language. For example if you write java games on mobile phones (a 64k jar on a nokia series 40), you need to have knowledge of what is big, what is not and what's slow or fast.

I remember having been contracted to do "some optimization" work on a J2ME game (a sort of arkanoid clone). I ended up nearly rewriting everything ... Well that was not very cost-effective for me but at least I had a good laugh. The original author of that particular program, for example was instantiating a new Date object in a loop that got executed several times in the main drawing thread.. just to get the current time from it. In a java game, if you want to know how many millisecondes where elapsed you can just call System.currentMillis() to get the current time in milliseconds. That's just one method, doesn't require allocating anything in memory and returns a simple value. If you just apply the example you were taught in class in the wrong context it gives such absurd results.

Someone who had only a very academic java course and no knowledge of the CPU work happening behind can only end writing monster bloated code. So yes at some point, learning some assembly is really a good thing. While I don't think you should start programming in assembly you should at least know it's the real thing and everything ultimately translates into opcodes and data being copied back and from registers.

For example in java or C code.. imagine a loop that adds oranges and apples to the fruit total. This will be executed several times in the loop so optimization is important (the fruits could get rotten if the loops is too long to finish :))

a) human thinking loop
for (int loop=0; loop!=1000; loop++)
{
fruits = fruits+(apples*sizeOfApplePack);
}

//while looking more compact is actually slower than

b) computer-thinking like loop

final int applesTotal =apples*sizeOfApplePack;
for (int loop=0; loop!=1000; loop++)
{
fruits += applesTotal;
}

Because once translated into java opcodes or machine language:
a) on EACH loop, 6 ops*1000 = 6000 ops
- load apples into CPU register B
- load sizeOfApplePack into CPU register C
- multiply register B by register C
- load fruits into CPU register A
- add register B to register A
- store back register A into memory address of fruits

b)
//Before the loop (done only ONCE)
- load apples into CPU register B
- load sizeOfApplePack into CPU register C
- multiply register B by register C
- loads fruits into register A only ONCE before the loop

//on each loop, only one op.. * 1000 = 1000 ops:
- add register B to register A

//after loop
- store back register A into memory address of fruits

Of course a smart compiler could cancel this difference easily. I was trying to make example simple enough so I could understand it myself :)
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
Very interesting thread!

It's certainly a question of aptitude. I'd like to think I'm a very good programmer, but an utter disaster area when it comes to keeping accounts and budgeting. I STILL can't figure out where "balance sheet" gets its name!
(Mine never do..)

One of the core skills in programming I believe is the ability to take a large, overwhelming problem and break it down into minute problems that you know you can fix.

So, instead of trying to build a house, you first figure out how to put one block on top of another without them falling down. Then, repeat until you reach the next problem.

It's as much about confidence in your ability as about skill. I'd estimate most developers have no idea how to accomplish their next project, but they're confident they'll do it by breaking it apart as above. Experience is the only way you'll build that confidence, and deadlines are the best motivation to get that experience!! I probably learnt more in the last 6 months of commercial programming than I ever did in several years of hobbyism.

One final bit of advice for any 'learner' programmers - if you're looking for a project to start off with, make sure it's something very simple, make sure you do it well, and most importantly make sure you finish it! It's a far more valuable and rewarding experience than attempting a more challenging project, doing it poorly and not finishing it.

Happy coding people! ;)
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
Mechcozmo said:
Your post took me a few reads, but I understand what it is saying in that code block. Really freakin' cool!

Yup, and it's all important to know. (Though it perhaps could use a brief explanation of what's a register, what's an opcode etc.)
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
MarkCollette said:
... low level code snipped ...

Oh kerrist, that brings me back. I remember writing machine code by hand for the 6502 microprocessor. One of the coolest things I did was add some machine code to handle user input (just to change direction using the arrow keys) in a centipede game written in Basic. Before I added the machine code, it was sooooo sloooooowwwwwwwww. Afterwards it was actually playable.

I miss that.

I was such a nerd.
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,782
7,514
Los Angeles
<soapbox>

I have "professional disagreements" with educators who think you should start with assembly language programming and work your way up. I agree with the "up" direction, but not with the starting point.

I think it's useful to learn about assembly language programming, and the fact that computers have registers, opcodes, instruction sequences, and what RISC, CISC, pipeline, multiprocessor, interrupt, and other terms mean, but I think it is not the best use of time for university students to spend weeks hand-writing their own SPARC code, as at least one university program I know currently favors. That's like having homebuilders grow the trees instead of starting by buying lumber. It's worth understanding low-level computer principles, but assembly-level coding, even for embedded systems, is less important each passing day and is better left for experts or specialists. It shouldn't be put there as an obstacle (which it often is) for beginning programmers.

That said, I think you appreciate and understand modern programming better when you understand what the machine actually does, what an interpreter like BASIC does, what a language like C or C++ is best (and worst for), and why languages like Java and Objective C have their current positions among our tools. To be well rounded, you should "experience" nonprocedural languages, scripting languages, etc., not to master each one, but to understand that programming is not limited to one language, tool, or approach.

Students who start with Java and then learn lower-level languages may think of lesser languages as stupid or frustrating, whereas students who learn "going up" (which is approximately the same as learning about programming languages in a chronological order) get a better feeling for how the evolution of languages has added convenience and safety to what we do.

</soapbox>
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
whooleytoo said:
Yup, and it's all important to know. (Though it perhaps could use a brief explanation of what's a register, what's an opcode etc.)

Hehehe.. Yes, thanks. I typed it all out on the fly, so I hope I didn't miss to many things.
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
Doctor Q said:
I read an article yesterday about the problems of learning modern programming languages. Programming languages have evolved much of the last few decades, but are often too complicated for beginners, and don't give a good feel for what the computer is actually doing under the hood.

The writer's theory seemed to be that students would do better by first learning an old, primitive language such as Fortran or plain BASIC (not a souped up object-oriented BASIC), before progressing to the languages we rely on today. When there is too much theory and too much complexity, students can't get that first "Hello, world" to run and get off to an unnecessarily slow start.

I'm not sure I agree with that, but I do know students who don't have a good idea how computers work, and just want to get their Java program working so they can turn it in by the due date. I've always been glad that I programmed in assembly language, C, and other low-level languages before I moved up the food chain, but maybe that's just because I feel more comfortable knowing how things work.

Some people are better suited to programming than others, but anybody with the time to devote to it should be able to learn some simple programming. I think more people would do well to start with a simple scripting language (and I don't mean AppleScript, which is not as simple to use as it is often made to sound), so that less effort is required to get the computer to do a few simple tricks, without all the baggage of learning object-oriented programming and a million rules about scope and structure. That can come later.

Do you have a link for that article?

I have first hand expierence in that. I started university as an Electrical engineering major, and graduate with a computer science degree. at this university CS was apart of math not engineer so a lot of the courses were seperate. The major difference was engineering school started their 1st years in Fortran, and CS started their students in Java. I went through both system for awhile. I don't think it really matters in the long run. for example, with fortran you get a better idea of hardware because certain in fortran regarding spacing, columns, and calls like rewind involve hardware issues. Java is an OOP language which gives more thought have structure and design. Most computer science school i believe now are expecting kids to have learned the basics of programming (loops, if, while, for etc) by their freshman year changing how programming 101 is taught. i think either philosphy is fine.
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,782
7,514
Los Angeles
superbovine said:
Do you have a link for that article?
I said "yesterday" in that post back in February, so I don't know if I can figure out what I was reading then, but I'll take some educated guesses and see if I can find it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.