Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

/prog/ feels thread

Name: Anonymous 2012-10-16 12:55

that feel when your CS lecturer starts loops from 1 instead of 0.

Name: Anonymous 2012-10-16 13:00

Lua is the future.

Name: Anonymous 2012-10-16 13:02

But numbers begin at 1. There's a reason first is `1st' and not `0th'.

Name: VIPPER 2012-10-16 13:04

If anyone ever gets to become an educator in programming, introduce loops that start from 0 and decrements.

Name: Anonymous 2012-10-16 13:11

>>1
Come on, this is no hard mental gym.

Name: Anonymous 2012-10-16 13:15

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)

Name: Anonymous 2012-10-16 13:33

>>6
yes, they are teaching us Java
It's not uncommon.

Name: Anonymous 2012-10-16 13:40

>>7
If I were the dean of the faculty, I'd have this professor fired on the spot.

Name: Anonymous 2012-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: Anonymous 2012-10-16 15:24

coding is not religion, freedom for iterations !

Name: Anonymous 2012-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: Anonymous 2012-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: Anonymous 2012-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: Anonymous 2012-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.

Name: Anonymous 2012-10-16 19:53

>>14
They hold different types of values.

Name: Anonymous 2012-10-16 20:27

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.

Name: Anonymous 2012-10-16 20:42

>>16
Pascal lover.

>>OP
Then politely as the Prof. to take the Final test now, and skip the class. No one should be taking java shit.

Name: Anonymous 2012-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.

Name: Anonymous 2012-10-16 21:15

>>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: Anonymous 2012-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.

Name: Anonymous 2012-10-16 22:00

>>1

typical luafag, completely glossing over superior javascript

Name: Anonymous 2012-10-16 22:17

typical javashit kike completely sucking cock turds shit fuck penis ass cock shit fuck nose penis ass cock shit fuck

Name: Anonymous 2012-10-16 22:23

>>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.

Name: Anonymous 2012-10-16 23:07

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.

Name: Anonymous 2012-10-16 23:42

>>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.

Name: Anonymous 2012-10-16 23:43

sizeof(x)
Seriously?

Name: Anonymous 2012-10-16 23:46

C'mon, 0 isn't an index, it's an offset.

Name: Anonymous 2012-10-16 23:49

>>24
lrn2c++11

for(auto& e : x)

Name: Anonymous 2012-10-17 0:00

>>25
flat address space
Not so fast...!

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.

>>26
char x[n];

[spoiler]Yeah, I did forget mah / sizeof(*x).

>>28
That is absolutely disgusting and I'm glad to be ignorant of it.

Name: Anonymous 2012-10-17 0:23

duuude you get some sleep and maybe you can close your tags properly

Name: Anonymous 2012-10-17 4:38

>>29
sizeof should never be used for loop indices. Never. It's incorrect.

Name: Anonymous 2012-10-17 23:37

>>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.

Don't change these.
Name: Email:
Entire Thread Thread List