Sure, but you had to think about it. And if you had accidentally typed i<=30 instead of i<30, you're now executing 31 times. On the other hand, a Ruby statement like "30.times" will execute, well, 30 times.
This is a trivial example, though. Let's say you have a function that collects sensor data and stuffs it into an array of indeterminate length. After collecting the data, you then want to print out the results, one per line.
In C, your code would look something like this:
Code:
float data_array[ARRAY_SIZE] ; /* The array that will hold our sensor data */
int sensor_measurements ; /* Holds the return value of collect_sensor_data(), which indicates how many measurements were collected */
int i;
sensor_measurements = collect_sensor_data(data_array, ARRAY_SIZE) ; /* collect_sensor_data() takes the maximum number of measurements so we don't overrun our buffer */
for(i=0 ; i < sensor_measurements; i++) {
printf("Measurement %i: %f\n", i+1, data_array[i]);
}
The equivalent code in Ruby would be:
Code:
sensor_data().each_with_index{ |value, index| puts "Measurement #{index + 1}: #{value}" }
The Ruby code is not only simpler and more compact, it's far easier to conceptualize. Why should a beginner need to know what a pointer is to complete a task like this, let alone understand how pointers and arrays are related in C? Making an absolute beginner learn stuff like this right off the bat is like teaching someone to fly on a 747. As splitpea said, you're best off learning the basics like flow control with a high-level language where you don't have to worry about managing memory, buffer overruns, pointers, and so on. There's time to learn about those things later, when you're ready to find out what's actually going on under the hood.
However, I don't think there's a problem with learning procedural programming, then object-oriented programming, and THEN digging down into the nitty gritty of the hardware. Many OOP languages so heavily abstract the underlying system that you don't really need to know anything about memory management and such in order to grasp the concepts. That said, I don't think you'll ever really
understand object-orientation without a grounding in the fundamentals of memory management and so on. A good programmer will need to know all of it, of course. But if you throw a beginner headlong into C right off the bat, that person may well end up not a programmer at all.