He also indents blocks by one space: class Main
{
public static void main( String args[] )
{
int i = 1;
while (i <= 5)
{
System.out.println("Hello world!");
}
}
}
(yes, they are teaching us Java)
>>7
If I were the dean of the faculty, I'd have this professor fired on the spot.
Name:
Anonymous2012-10-16 15:07
>>7
I know that it's very much the standard, but it's wrong. It's the third week and he only just touched on methods. If this were C, we'd be on malloc/free already.
>>8
Meh, he's not that bad. The other thing that irked me was when he referred to variables as boxes and said that double and int are different types of memory. They're not, they just occupy different amounts of memory, and the compiler handles each differently, but it's an abstraction, they're really the same at the lowest level.
Name:
Anonymous2012-10-16 15:24
coding is not religion, freedom for iterations !
Name:
Anonymous2012-10-16 15:29
>>9
It's an abstraction, like everything else in CS. When you start a machine level or compiler class is when the distinction begins to matter (though you should obviously know this long before it comes to that).
Name:
Anonymous2012-10-16 15:34
that feel when right-wing politicians, the big media ,,industry'', paranoid parents and evil governments are out to get your digital freedoms
Name:
Anonymous2012-10-16 15:56
that feel when the old guys come and spray shit in the toilet and it dries and it takes forever to get off and the company is too cheap to by some chemicals
Name:
Anonymous2012-10-16 16:08
>>11
But it's not just abstraction when you say that things are something other than what they really are (I apologise for that clumsy English), it's misinformation/oversimplification. I know I'm splitting hairs but programming has to be very precise. Being imprecise in your teaching causes programmers to be imprecise in their thinking which leads to bugs which cause things like the Ariane 5 near-disaster.
One-based arrays and loops are more natural because empty arrays exist in nature. The first N numbers are 1,2,3...N. The length of this list is N, the upper bound is N and the maximum value is N. If N is 0, the list is empty. If arrays start from 1, the upper bound and length of any array are the same. For an empty array, the upper bound would be 0. No negative integers are necessary for one-based arrays, so anything involving array indices or lengths can be unsigned. Inclusive ranges are also more natural. When someone mentions lowercase letters, you think "a".."z" and not "a"..chr 1+ord "z". If you consider a loop over the integers included in a one-based numeric range, such as 1..10, the loop will repeat as many times as the second integer. With 1..1 it loops once, and with 1..0 it is not executed at all.
>>OP
Then politely as the Prof. to take the Final test now, and skip the class. No one should be taking java shit.
Name:
Anonymous2012-10-16 20:48
that feel when your CS lecturer starts loops from 1 instead of 0.
Using 0 or 1 to begin loop counts are simply a matter of convention. Starting with these numbers are equally as arbitrary as starting with any other.
>>16
I happen to think of "a".."z" as ord("a")..ord("z").
What's this about negative numbers? Zero isn't negative. There's nothing to index in an empty array.
The range argument is worthless. It's just pissing about preference of open-vs-closed sets.
Finally, it's 2012. You can dispense with loop counters in whatever shitty language you're using. Dat lambda.
Name:
Anonymous2012-10-16 21:54
Some languages have a function that returns the first index of a substring in a larger string. With one-based arrays, it returns N if it begins at the Nth character, or 0 if the substring can't be found. With zero-based arrays, it returns N-1 for the Nth character (such as 0 for the 1st character), otherwise it's usually either -1 or one more than the length of the string. Using signed numbers cuts the maximum string length in half. Consider using these results as booleans. What's more natural?
Think about C's null pointer. This is an address with a value of 0, used in the exact same way 0 is used with one-based arrays in the previous example. You can't dereference this null pointer even though it's a possible pointer value, just like you can't index a one-based array with 0 even though it's an unsigned integer.
>>20
It's funny you'd bring up sentinel values and C in particular. C has very good reasons for using 0-based arrays. C has just such a function you describe, but it just returns a pointer into the array like a responsible adult. Your language doesn't have pointers? Some(x) | None | Bust.
Seriously though, this in-band signaling BS is only good as a feat of engineering. You don't want to have to do that in your language.
Hardware description languages have composite types that can be indexed over any range. When most operations are unordered and apply to the whole array at once, who honestly cares what the base is?
Doesn't anyone else get tired of typing for (i = 0; i < sizeof(x); i++) all the time instead of for (e in x)? Even C compilers are expected to transform loops now; there's no reason for it to exist anymore.
>>4
I hope you mean to start at n and decrement while testing for zero. This is usually more ``natural'' from the machine's point of view.
>>23 You don't want to have to do that in your language.
This is so very true. Even in C, returning an error code in band is almost never the right thing to do. Even if you can't currently think of a case where the range of the function could contain the sentinel value, it's very likely that you will later. Better to just use an out parameter and return 0 if you can't immediately think of a failure case.
>>23
What is a null pointer in a flat address space? It's the 0 index for the char array of memory. C's memory array and one-based arrays have the exact same use of 0 to mean an empty value or out of bounds index.
NULL isn't guaranteed to be zero. It is guaranteed to compare equal with zero. Casting NULL to integer type may give you absolutely anything. This is important to consider when dealing with segmented architectures where the bottom of an arbitrary segment needs to be addressable.
>>31
If x is an array type, sizeof(x) gives the size of the array in chars. K&R even uses it as an example of how to define useful macros,
#define NELEM(x) (sizeof(x) / sizeof(*x))
You're probably confusing this with the case where sizeof is given an argument of pointer type. This is what happens when an array is passed as an argument to a function: array types decay to pointers so they can be passed by value. Then sizeof will give the size of the pointer, which is probably not what is wanted.