Go Down

Topic: BEGINNERS: Think of everything as a function() (Read 2473 times) previous topic - next topic


...can write a dumb code 100's of lines long that are designed to be read by a newbee when I know they could have just typed a few lines that would take a newbee a week to understand.
I agree. My experience is that examples are best retained if the beginner: 1) can relate to the example, or 2) enjoys how ridiculous it is. For example, I explain a function call in terms of them "walking through" the code. If they see this:

int x;
int y;

// some code that sets the coordinates

   lcd.setCursor(x, y);

I tell them when they see this last line, take the two bytes for x and put it in your backpack, take the two bytes for y and also put it into your backback. Now scurry off and find the house named lcd. Once you find the lcd object in memory, use your key (i.e., the dot operator) to open the front door and find the room with setCursor() on it and knock on the door. (I refer to class properties as people sitting in the living room.) A hand will quickly appear from the door, grab your backpack, quickly disappear, and the door closes. A few milliseconds later, the door will open and the hand gives you your backpack, and you are instantly transported back to that line where the journey began. You look in your backpack, and find it's empty (void), so you move to the next line.

While this example is silly to us, it is easily grasped by a 12 year old because they have experience with backpacks and being told to go somewhere. It also reinforces the idea of encapsulation by referring to the dot operator as a key that lets you gain access to the "house" (i.e., object) and that methods and properties are only available once you're inside the house.

My experience is that super-bright people are often crappy teachers because they can't appreciate how some things are difficult for beginners to understand. Fortunately, some people (e.g., Nick) are both bright and good teachers, but they are rare.


I nowadays mostly write C# code for Windows systems for a living. My code is basically just C with some C# sauce.

I agree, I should quit and do some woodworking :)
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.


I pointed this out as one of the best examples of RDC (i.e., Really Dumb Code) I had ever seen. I noticed several programmers cringe when I said it. I was fired the next day. Evidently the person who hired me also wrote the code.
At which point, every other proogramer there should have immediately started looking for another job.


"What's a function?"

I mean, it's fine advice, but functions are a relatively advanced concept in programming, especially for the arduino target audience - we regularly see questions like "how can I make another void, like loop?"
I know not everyone agrees, but when I see a thread like this my response is always "go do a free C++ tutorial - there are thousands to pick from".


I know not everyone agrees, but when I see a thread like this my response is always "go do a free C++ tutorial - there are thousands to pick from".
I certainly agree: (OP here)... but the masses don't even think of searching for a suitable tutorial - let alone actually spend time doing one!  I'm just trying to trickle feed some of dubious experience!
When posting - use the toolbar and read the stickies if you're not sure!

Go Up