![]() |
Why I hate c
Code:
void User_Autonomous_Code(void) |
Re: Why I hate c
I totally agree. I'm a professional software engineer with 20 years experience. C is such an unforgiving language. It is difficult to read, easy to make simple errors in syntax, and most compilers won't warn you about things like:
Code:
Process_Data_From_Local_IO;Code:
if (myvar=0) |
Re: Why I hate c
Quote:
Code:
if(0 = myvar) |
Re: Why I hate c
also the reason
Code:
Process_Data_From_Local_IO;Code:
x++; |
Re: Why I hate c
Using a utility like Lint can help with those sorts of errors. Just run it and it will warn you of anything that you probably didn't mean to do.
|
Re: Why I hate c
Code is only as readable as you make it. Make names self-explainatory (or close to it). I tought myself VB, and my naming conventions are based on that.
|
Re: Why I hate c
Quote:
I'm going to a talk by Brian Kernighan next week -- I'll give him your regards! ;) |
Re: Why I hate c
Quote:
under the MPLAB C18 tab "Diagnostics level" you can chose "errors, warnings and messages" and get more dianostic info, but it won't catch it all. |
Re: Why I hate c
Quote:
Code:
while(*t++ = *s++);Code:
if ( my_timer == 0 )Code:
if ( !my_timer )And don't get me started on how numeric operations are performed using the smallest size that the operands will fit in, leaving me to worry about overflows even if I know the end result of an expression will always fit in the variable I'm putting it in. Oops, too late... I apologize. It was a late night last night. And I must admit that the tool does get the job done, with little to no fuss, as long as I remember to use it correctly. |
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
--EDIT-- P.S. Sorry for double posting there. :) |
Re: Why I hate c
Quote:
Quote:
Quote:
all in all, most of the faults you described are with this specific implementation of C. Chances are you would find programming for a regular computer with C much nicer. |
Re: Why I hate c
C is one of my favorite languages. While it can be VERY unforgiving at first, it's not too difficult once you get used to the language. I used to make lots of simple errors (forgetting parentheses, failing to end statements with semicolons, etc.), but the frequency of that sort of error decreases significantly once correct C syntax becomes habitual. C is tremendously powerful without being nearly as arcane as assembler; it allows one to easily combine useful low-level operations with high-level procedural and algorithmic code in a syntax that's clear and human-readable. It took me a long time to get used to C, but I now find that it's my language of choice for many programming tasks. Don't blame the language because you made an error. Certain errors may look like obvious mistakes once you find them, but those errors are often similar or identical to operations that one might perform in order to obtain useful results.
For example: Code:
if(file_handle = fopen("foo.bar","r")) |
Re: Why I hate c
Quote:
Yes, c is very capable. It is also very terse. In sufficiently skilled hands, that's a powerful combination. In just slightly less skilled hands, it's a recipe for subtle errors. As for me, I prefer to use a language which is a bit less terse, with syntax that doesn't make it quite so easy to shoot yourself in the foot. |
Re: Why I hate c
What do you mean by "single equality sign in a conditional"? Isn't = an assignment symbol?
|
Re: Why I hate c
Your inability to detect problems is in all likelyhood related to the self rather than the language. Personally, if I can't solve a C/C++ bug within 5-10 minutes, I ask someone who also knows it to look over the language, because they find things I miss. And good compilers do make a good deal of difference. Personally, I like C++ because I like object-oriented language, but C is better than visual whatever they were using before. You can do so much more with so much less. Plus, knowing it has broader practical applications.
|
Re: Why I hate c
There's a way around that (sort of): Something I call "psuedo-objects". Basically, For each instance of the object, Copy the code and declarations and rename. And replace dots with underscores. Object_Procedure
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
I know that, but generally isn't "If (foo=42)" what one tries to avoid?
|
Re: Why I hate c
Quote:
The reason C compilers don't typically give warnings or errors for using the single equals sign inside a conditional is because it CAN be valid. In the code I posted, the single equals sign sets the address of a file handle, whose value needs to be inequal to zero in order to work. Yes, it's one of those annoying tricks used by programmers who like being clever (i.e. me), but my point is that it's valid and there's no reason the compiler should label it as a syntax error. |
Re: Why I hate c
Some compilers will give you a warning if a condition will always be true or always be false.
|
Re: Why I hate c
Off topic... but I gotta say...
Alan, you made a great program. While you were at work yesterday, we started making automodes. Your software system enabled us to create 5 workable automodes within about 6 hours. These are 5 modes that work, at least on our field. The code was so clear that even I could tweak the numbers. To the rest of you, get this: Alan was just an interested parent who attended meetings a few months ago. We needed some more talent in the software area and he rode in on his white horse and saved the day. Thanks Alan!! Welcome to the craziness of FIRST! Andy B. |
Re: Why I hate c
I'm proud of Andy for working on the auto modes :)
|
Re: Why I hate c
Quote:
That is... of the dark side of the force... forever will it dominate your destiny. Baker is now tainted goods.... Remember kids: Do not fall to the Spark Side. ;) Gearboxes are more fun. John |
Re: Why I hate c
Quote:
Sooner or later you will learn that you can't resist the natrual urge to become one of us. We have Baker now, and you're next! *evil laugh* Seriously, isn't C much nicer because now you Gearheads no longer have an excuse about not understanding the basic operations of the language? Steve |
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
Not to mention PCs, which may have a bigger market than embedded systems; C++ is the standard there, too (Though VB is good for a quick dev, I made a program in 10 minutes in VB).
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
PIC C isn't object oriented like MSC++, which means that you don't have classes and the code Object.Method(Args); is invalid.
|
Re: Why I hate c
Quote:
If you are using a new compiler, one of the first things you should do is see how the warning levels are set, and then set them to how you like them. As people have been finding out, C allows a lot of "strange" things as valid syntax, which is done to increase flexibility and the speed of the language. However, this can lead to some confusing run-time errors. This is why C compilers have warning messages in addition to error messages. If you use the warnings properly, you shouldn't have much issue. Another point: C is like anything else in life: you're not going to be good at it until you practice with it. You'll make errors, you'll find the errors, and then you'll start learning where to look for future errors. In the future, you'll begin to recognize certain behaviors that will help you pinpoint the errors. You know, "hey, I've seen this type of thing before". Just because you've all hit a few stumbling blocks on your first attempt at C doesn't mean it's a bad language. It just means you're not used to it. Give it a little time and you'll soon be wondering how we ever survived with pBASIC. Also: Has everyone been taking advantage of signed math? I sure hope so. It is probably the biggest advantage of the new C compiler vs. the old pBASIC controller. |
Re: Why I hate c
My first roadblock in learning C(++) was the complexity and the amount of "Valids" vs. "Invalids".
Haven't needed signed math. Well, I did write an abs() function for variance stuff. |
Re: Why I hate c
Quote:
If you are doing any serious control loops (a PID feedback control on a robot arm for example), signed math is a real time saver. But... ...C is a language for consenting adults. You can get into a lot of trouble if you are a casual user. Joe J. |
Re: Why I hate c
Quote:
I like C because it let's you do so much, though I agree the single = sign in if statements should probably throw a warning. But I've used it so much now I can usually trace errors like that fairly quickly (or avoid them altogether). |
Re: Why I hate c
All the above discussion is exactly why here in my world, we don't write software by hand any more. It is easy to produce bug free C code that does exactly what you want every time if you have the right software tools. We use an Autocode generator called Rhapsody by I-Logix to generate all of the code we use for the interior systems of all DaimlerChysler vehicles. We write code in a graphical state-machine format and the code generators translate these models into embedded C. In the near future, most software will be developed this way. Now that we have moved from Pbasic, we can apply these methods to robots. I autogenerated the software module for my shift scheduler on BUZZ9 and it dropped right in.
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
Does anyone within the sound of my voice have an "in" with Mathworks? I know this would be a huge huge huge step forward in terms of programming robots. Think of how easy it would be to program if you actually had models of arms, motors, Victors, Spikes, valves, cylinders, etc. all ready and waiting for you to drag and drop? You could code your robot before you actually had a robot in stead of what we have now which is the mechanical system gets done in 5.9 weeks, the wiring gets done in .09 weeks and the programmers have .01 weeks to make it all behave. There are a lot of things that are unfair about the FIRST competition, but the stress that we tend to put on the coders is among the unfairest burdens we put on people in this FIRST game. If anyone can get Mathworks to fall in love with FIRST, we would be a long way to making it up to our poor coders. Joe J. |
Re: Why I hate c
Heh, this is possibly off-topic since the thread has wandered slightly from hating C, but here's a beautiful piece of C code and explaination that I snatched from the hacker's dictionary.
Duff's device: n. The most dramatic use yet seen of fall through in C, invented by Tom Duff when he was at Lucasfilm. Trying to optimize all the instructions he could out of an inner loop that copied data serially onto an output port, he decided to unroll it. He then realized that the unrolled version could be implemented by interlacing the structures of a switch and a loop: Code:
register n = (count + 7) / 8; /* count > 0 assumed */[For maximal obscurity, the outermost pair of braces above could actually be removed — GLS] Heh. Took me a minute to wrap my head around it, but I think it's nifty. |
Re: Why I hate c
Quote:
I guess my discomfort with c boils down to the fact that it's a low-level language in high-level language clothing. It's not far removed from assembly language. I do understand the reason for its being that way. That doesn't mean I have to like it. :rolleyes: |
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
It is my understanding that Mathworks is still privately owned (ie no stockholders) so it may not be that difficult to get the owners, who are programmers themselves, to agree to help FIRST. They already heavily support academics since MATLAB really got its start in universities. Great Idea Joe! Hope some one can follow through on it. |
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
As I've mentioned before, things are starting to move more toward auto-coding, but this is made possible due to faster, cheaper microcontrollers that can make up for the more inefficient code. However, there is still a high likelihood that we'll be using C for quite a while since there will always be an ultra-cheap product that needs to have too much code crammed into a tiny micro. One last thing about auto-coding: Auto C code generation is just another step up the auto-coding ladder. It's not that revolutionary. Think about it: what is a C compiler other than an auto-coder for assembly language? People used to program with only an assembler. Now the standard is to let the C compiler auto-generate the assembly code and THEN let the assembler go ahead and make the machine code. The next level up is to let TargetLink create the C code, then the compiler creates the assembly code, and so forth. |
Re: Why I hate c
Plus, if you go into PC programming, there's a lot of C++ around. Plus, lets face it, pretty much only assembler is harder than C/C++.
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
Wow! So it's not just me ... sounds like it would be cool to learn about, but I'm a little weary about letting some computer output a program for me! Quote:
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
I had to toss this in. It's my favorite bit of obfuscated C -- a program written to be incomprehensible. (I didn't write it -- I don't know who did.) I guess what's "bad" about C is that it lets you write code like this. But this code is masterfully written by someone who knows the language very well -- maybe a little too well.
This will compile and run on a command line, printing a message. It looks scary, but it's harmless. The output will astound you. Here's a hint: Merry Christmas! /Norm Code:
#include <stdio.h> |
Re: Why I hate c
Cryptic code can be acceptable if:
1. You are the only person who will ever look at the code, and you are used to seeing this kind of cryptic code. 2. You know the people looking at your code (teammates, coworkers, etc) can understand it. 3. You need process and memory-optimized code, because you are working on a system with a relatively slow processor and relatively small memory (The RC, for example). Remember, though, you should _ALWAYS_ comment your code, especially if it is cryptic. What if your grandmother (who I'm assuming doesn't know C) wanted to read and understand your code? |
Re: Why I hate c
If you really want to see some obfuscated C code, there's actually a contest for it. http://www.ioccc.org/ - The International Obfuscated C Code Contest.
Winning entries can be found at http://www1.us.ioccc.org/years.html If you want a language that is very easy to program in and makes sense, check out Ruby at http://www.ruby-lang.org For example, to run a command 3 times in C, you would do this: for (int i=3; i<=0; i--) { command(); } In Ruby, it would look something like this: 3.times { command } Ruby is also loosely-typed, meaning you don't have to worry about the size of the variable that's holding your data, the interpreter will determine that for you. Note that you can't use Ruby on the robot, this is just for hobbyist programmers. |
Re: Why I hate c
Thanks for that pointer to IOCCC -- I think that's where that bit of code came from, many years ago.
And now I'm reminded of another language, "whitespace,", wherein all code is composed entirely of three characters: space, newline, and tab. Here's a example bit of code: Code:
This is a comment. |
Re: Why I hate c
Quote:
By the way, what does your program do? |
Re: Why I hate c
Quote:
Code:
short main[] = {this is from the first IOCCC competition in 1984 |
Re: Why I hate c
Quote:
|
Re: Why I hate c
Ditto on both of those and Deltacoder's
|
Re: Why I hate c
If you really want to see a pointless language, check out Befunge(http://kotisivu.mtv3.fi/quux/befunge.html); they call it a '2 dimensional, lower than assembly' language. Scary thought. Here's a bit of code:
Code:
>1+>:~::"0"-:v>$:v>>21p :0#v_1-::::6g:" "-!88+*+vAlso, Assembly is by far not the lowest language. Many programmers (decades ago) have programmed by punching holes in punch cards, using direct binary values, and even wiring vaccuum tubes together to perform a specific task. |
Re: Why I hate c
Quote:
|
Re: Why I hate c
Quote:
|
Re: Why I hate c
MPLAB need i say more
|
Re: Why I hate c
Code:
"d"v >v |
Re: Why I hate c
Its like an artform
Code:
"d"v >v>"e",v |
Re: Why I hate c
All I can say is "Weird..." :)
|
Re: Why I hate c
I'm another one of those intellectual masochists who love C. The biggest perk for me is how much control C gives you over both the internal workings of your program and the shape of your code itself. It has strong typing, so you can specify how big and fast you want your variables to be. It has pointers and references, so you can pass actual variables to functions rather than just the values of variables. It has structures, so you can organize data into big, meaningful chunks and create data types with sizes that exactly suit your needs. It has bitwise operators. It has functions with return values. In a desktop environment, C gives you even more control, with register variables, dynamic arrays, and in-line assember code (if you really want to beat yourself up ;)). C may be a little more unforgiving than some other languages, but I find that most of my stupid mistakes come from program structure, not syntax -- whether I'm coding in C, Java, Javascript, Perl, or PBASIC, I make the exact same amount.
|
Re: Why I hate c
Quote:
p.s. sorry bout the double-post :( |
Re: Why I hate c
Quote:
|
Re: Why I hate c
I love C, but I'm kinda sick in the way that assembly is my favorite language (despite the fact that I don't know too much of it). I like languages that make logical sense. I hate VB, it's absolutly awful. For instance:
"if cheese = 0 then" compared to "if (cheese == 0)" the second just makes sense to me. The first, it's like "Wait, so am i setting cheese equal to zero, or am I just comparing it?". Once you study C, you see the merits to how it behaves and why. It's much more logical than VB once you understand it. In order to gain a true appreciation for C though, you need to study C with assembly. Only then is the true beauty of C revealed. |
Re: Why I hate c
I have an advantage: I learned VB first. But it's really nice for making small/micro apps. Like one that finds the factors and prime factorization of a number.
|
Re: Why I hate c
Don't put down VB I admit that C may make more sence but VB still has the advantage of simplicity. It is point and click. I mean sure the code is not exactly the best but it is still easy once you know how it works, just like anything. It is easy, but only after you know how it works.
|
| All times are GMT -5. The time now is 00:14. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi