Page 1 of 4

C sucks (RANT ALERT)

Posted: Wed Oct 03, 2007 8:51 pm
by Trond
C sucks. Example:

Code: Select all

int *pint = 1234;
int *litre;
*litre = 1234;
Now why the HELL does *pint = 1234; set the value of the POINTER while *liter = 1234; sets the value of the DEREFERENCED POINTER???

And WHICH IDIOT made a SYSTEM programming language WITHOUT putting the BIT SIZES of the standard types into the standard? A valid 32-bit C compiler for x86 can, while following the standard, have an 8-bit int and a 64-bit long long (as long as a short and char is no more than 8 bits either). Only conventions keeps the programs running, not the standard.

Code: Select all

int *ptr, notptr;
C's pointer "system" (where's the system?) is a total mess. The * belongs to the variable, not the type, so notptr will not become a pointer. However, even though the * belongs to the variable and not the type, it can also be specified when you specify only a type and no variable, like in a function prototype:

Code: Select all

void myfunc(int *);
In one declaration the * belongs to the variable, in the next it belongs to the type. What were they thinking? (Were they even thinking?)

When to use the * is confusing for starters because it means the EXACT OPPOSITE in different parts of the program.

Code: Select all

int * here_it_means_i_want_a_pointer;

Code: Select all

*however_if_i_use_it_here = it_means_i_DONT_want_the_pointer_but_the_value_it_points_to;
Maybe the other features of C are good, then? (Does C even have other features than pointers?) C features a rich set of operators, that's good. But wait a minute! Did I just say a "rich" set? Can anyone tell me why on earth C lacks a non-bitwise XOR operator? (And C++ as well.)

C has 15 levels of precedence (C++: 17). How many C programmers remembers the relative precence of bitwise and compared to bitwise or? Not many.

To be "consequent", C does not use = for equality testing, it uses ==. This is a huge source of hard-to-detect program errors for programmers. But at least it's consequent, right? Not really. Because when you type a <= b you actually do use = for equality testing, even though = means assignment. If this system was truly consequent then <= would be to < as += is to +, and do an assignment of the boolean value of a less-than comparision.
Yep. += adds and assigns.
-= subtracts and assigns.
*= multiplies and assigns.
/= divides and assigns
%= does modulo and assigns
>>= shifts right and assigns
<<= shifts left and assigns
&= does bitwise and and assigns
^= does bitwise xor and assigns
|= does bitwise or and assigns
<= does NOT do a less-than comparison and assigns.
And they did this to be consequent? (By the way, why is there no &&= operator?)

Posted: Wed Oct 03, 2007 9:20 pm
by milan1612
Quite interesting to read this, but I think every language has small inconsequences.
Even PB:
I've always wondered why, if you want an infinite loop, the 'Repeat' must end with 'Forever'
and not 'EndRepeat' :lol:

Posted: Wed Oct 03, 2007 9:45 pm
by Trond
Because EndRepeat means that the repeat should END. However, you want to continue with another iteration. :wink:

Posted: Wed Oct 03, 2007 10:12 pm
by blueznl
It's all about form and style, man.

As in GfaBasic's implementation:

Code: Select all

DO
  ....
LOOP

Posted: Wed Oct 03, 2007 10:16 pm
by blueznl
It's all about form and style, man.

As in GfaBasic's implementation:

Code: Select all

Do
  ....
Loop
... but Pure's looks better :-)

Code: Select all

Repeat
  ....
Forever
The command I still feel funny about is While ... Wend... I think the next version of PureBasic should restandardize and call it...

Code: Select all

While ...
  ...
GoBackToThePreviousLineWithTheWhileAndKeepTryingMate
Much clearer.

Posted: Wed Oct 03, 2007 10:25 pm
by milan1612
Well OK, actually you're right :lol:
Just needed an example and remembered that in the beginning
of my PB 'career' I felt confused about the 'Forever' :roll:

Posted: Wed Oct 03, 2007 10:38 pm
by Xombie
This is something I've always wondered about: Why does a language need to be so complex as C/C++ and such? Seriously. It just seems that you could create a language that is allows for a high level of customization without resorting to so many hacks and 30 different ways to accomplish something. I look at some C code and cringe from how needlessly complex it seems.

Or DirectX. My god that is horrible to look at. Why can't it just be something like... "InitEnvironment()" or "SpotlightHere()" or "PlaySound()" rather than 500 lines to do something relatively simple.

Am I just being naive?

Posted: Wed Oct 03, 2007 11:03 pm
by milan1612
No, you're not naive. It's just, well...let your code look more complicated
then your wages will increase :lol:

Posted: Wed Oct 03, 2007 11:08 pm
by r_hyde
I'm in the middle of translating thousands of lines of C code into PB, and I honestly have to agree with Trond about C's usage WRT pointers. However, I will say that I prefer the ease of dereferencing using a single operator rather than PB's Peek/Poke functions. There has to be a way to make pointer usage both consistent and simple/wrist-friendly!

Posted: Wed Oct 03, 2007 11:52 pm
by PB
> For a new monitor nail here [x]

That's pretty funny. :)

Posted: Thu Oct 04, 2007 3:40 am
by Rook Zimbabwe
And WHICH IDIOT made a SYSTEM programming language WITHOUT putting the BIT SIZES of the standard types into the standard?
:oops: OK it was me... :oops:
:D and if you believe that I have a dereferenced pointer set to localize!!!

Yes, there is a different sort of logic to C than Basic. I have trouble thinking in C, but little organizing my thoughts in BASIC.

However, as long as you are accurate in your pointage and ; use... you can do some amazing things... Look at the C code in the OBFUSCATION thread!

And then code more in PB... 8)

Re: C sucks (RANT ALERT)

Posted: Thu Oct 04, 2007 9:03 am
by traumatic
[SOLVED]

Posted: Thu Oct 04, 2007 10:33 am
by Trond
r_hyde wrote:I'm in the middle of translating thousands of lines of C code into PB, and I honestly have to agree with Trond about C's usage WRT pointers. However, I will say that I prefer the ease of dereferencing using a single operator rather than PB's Peek/Poke functions. There has to be a way to make pointer usage both consistent and simple/wrist-friendly!
But you don't need Peek/Poke. Just use a variable called *Pointer.LONG. *Pointer is the pointer and *Pointer\l is the value.

Posted: Thu Oct 04, 2007 11:59 am
by Psychophanta
Yeah! Confirmed: C and C++ are crap :)

Re: C sucks (RANT ALERT)

Posted: Thu Oct 04, 2007 12:30 pm
by citystate
traumatic wrote:[SOLVED]
now, don't let's start THAT again... :lol: