Why is writing C so hard!

Fusengammu

Registered
Okay, I'm not a REAL programmer (I know java, js, you know, fluff languages), but I did read K&R's "C" book way back when. my question is, why are actual UNIX C programs out there so hard to read and compile? i guess it is because of the fact that they were written to compile on like a billion platforms, but it seems to me 50% of the syntax and grammar I see in the source code for these programs don't resemble any sort of C program I would ever write...

I don't plan on doing programming professionally, but I would like to be able to work or at least play with open source code. Does anybody know where I can find some documentation on how to decipher real world C programs for UNIX?
 
lol I resent you calling java a fluff language :p
shame on you...you have incured the wrath of teh Admiral :p :p :p

well quite simply C is a retard kind of language ;)
I HATE C :p
 
Arrr! Admiral, now you've incurred the wrath of Junior Member Shrill!! :p

C is the best language around: It runs on everything, it let's you do high level without a weirdo scripting language OR low level programming without an assembler! More than that, from the ashes of C spawned C++, Java[script], Perl, etc. Most (all) modern languages are either direct descendents of C or use C's syntax rules.

That being said, I don't use C much anymore, it's too hard :D I'd rather use perl.

Back to the original question: you're right, Unix C programs can and do run on virtually every platform, are usually written by several people (speaking several languages) via CVS, and have astronomically complex makefiles and such. They aren't meant to be read by Mere Humans. I think you find your documentation for most of them by taking computer science courses at MIT.


I'll concede one point though: without C, there would be no C++; without C++, there would be no MFC; without MFC, Windows would still be Dosshell, and the Evil Empire would still be a Star Wars reference. :p~
 
ANSI C just sucks,
if you clain that C gave rise to other languages, then fine, assembler gave rise to B which gave birth to C, heck, lets go back to punchcards :p

I hate memory manipulation in C, memory management, no automatic garbage collection, no automatic memory allocation, ANSI C is junk :p
 
--> If you are a real JAVA programmer, learning C or C++ is not much of a stretch. Pick up one of those "learn C in 10 minutes" books. <--

I WAS a Java programmer professionally for 2 yrs, and I worked inside a big project, so I think I'm pretty real as a Java programmer. And the first language I learned to program in was C. I mean Java is a fluff language because its so easy to use even a doofus like myself can use it. :p

What I meant in the first post was, reading through UNIX source is often an indecipherable experience. Since I don't have any source code in front of me, stuff of the top of my head:

* I remember trying to compile something on my box, and I got a message like "unistd.h not found." Okay, so I find it on my OS X box, and then include it in my include file search path. Then it complains about how some function has duplicate definition, but the two defs have different return types. ?? Question, how to learn about what to do then?

* How does one decipher all those #ifdef stuff?

* I have no clue how variable visibility across separate source files work in C. In Java, anything "public" is visible everywhere. In C, theres all this static, extern, etc. etc. VERY VERY confusing.



I hope to never program professionally again, but I still want to be able to program for fun, and maybe one day learn enough to contribute to open source. But the more I read through UNIX source code, the more I have no clue wtf is going on???


--> Back to the original question: you're right, Unix C programs can and do run on virtually every platform, are usually written by several people (speaking several languages) via CVS, and have astronomically complex makefiles and such. They aren't meant to be read by Mere Humans. I think you find your documentation for most of them by taking computer science courses at MIT. <--

I guess that's what makes the world of UNIX so diverse, mysterious, contradictory and attractive to me.:)
 
ANSI C sucks :D


"unistd.h not found." Okay, so I find it on my OS X box, and then include it in my include file search path. Then it complains about how some function has duplicate definition, but the two defs have different return types. ?? Question, how to learn about what to do then?

Usually you stomp your feet and sware a lot. Sometimes the header files from one framework get in the way of the header files from the other framework, and you get conflicting definitions. Sometimes you can fix this copying the definition that you think is right into your source file, and by not #including the second header file. Somebody probably has better advice on this one :eek:

* How does one decipher all those #ifdef stuff?

Most of the time, #ifdefs are used to separate out platform specific code. You mainly have to find out which #ifdef applies to your platform and ignore the rest. They are also often used as workarounds for difficiencies in compilers that are found on various platforms (you probably won't have to look too far to find "#ifdef __FILENAME__" in a .h file, which is a workaround for compilers that don't have something similar to a "#pragma once" directive).

I have no clue how variable visibility across separate source files works in C. In Java, anything "public" is visible everywhere. In C, theres all this static, extern, etc. etc. VERY VERY confusing.

> File1.c
static thing thing1; /* can only be referenced from within File1.c, because it's declared static */
extern thing thing2; /* this can be used in File1.c, but it's extern, which means it's declared elseware */
thing thing3; /* this thing is declared here */

> File2.c
extern thing thing3; /* refers to File1.c's thing3; the reason this works is because thing3 is global, and there can be only one thing named thing3. */
 
Yeah shrill, perl's real easy to read. :D

I learned C++ in high school but I'm kinda rusty now. I took two computer science courses this year but neither had any real programming in it. So I'm stuck doing recreational projects in Python (not that I'm complaining; Python is fantastic) until I can rustle up the free time to work on my C.

-the valrus
 
Any language can be obfuscated. Even Python. If you write code well, any language can be clear, also.
 
I am learning C and assembly . I spend like 6 months on 6 months off .

I like taking a break from things , learning C in university is a few year course and I dont have all the time in the world but I am finishing off my basic studies of C and assembly completing a few solid years of computer studies .

To be able to write competant code you have to be creative in math to get anywhere . I am going to do some math studies this summer with algorithms and such . I want to work on my own code , which I think draws many people into computer science .
 
I wonder if there's not some sort of pissing contest among Unix programmers to see who can come up with the most terse, obfuscated way of doing things.

Sometimes you puzzle through someone's code, full of embedded ++'s and --'s, and you realize that it's nothing hard, and could be easily expressed by adding one local variable and three lines of code...
 
lol code compactness seems to be the thing :p
When someone programs in any language, a three-lined version might have a abigger "Big-oh" (time complexity) than one line of code (i.e. using a loop to calculate some number rather than figuring out some formula in order to keep time constant)

optimization of code sux at times:p


Admiral
 
Originally posted by testuser
If you are a real JAVA programmer, learning C or C++ is not much of a stretch. Pick up one of those "learn C in 10 minutes" books.

I recommend "Learn C In 25 Seconds, For Dummies" :D
 
It might be a pissing contest among unix programmers, but I'm not really a unix programmer, so I can't say.

perl is my favorite for two reasons, both of which have to do with the way it looks:

1. A page of perl code doing some good stuff looks like what I think a page of code should look like. Lots of symbols and punctuation arranged in some strange order. It reminds me of my bewilderment on seeing my first page of C code. I had no idea what all those semi-colons and curly braces where. It scared me. It looked confusing and *really* hard.

2. perl looks impressive to the casual over-the-shoulder passerby - programmer or mere human. Someone might come up behind you, about to ask "Hey, are you busy?" but the arcane perl symbols ~!@#$&%^$()//;\\ all over the page makes them think, "Wow, you are doing something *really* hard and *really* important, and what I had to say wasn't really that important, and boy I feel dumb looking at that stuff." Then they just leave.


- shrill -



@a=(Lbzjoftt,Inqbujfodf,
Hvcsjt); $b="Lbssz Wbmm"
;$b =~ y/b-z/a-z/ ; $c =
" Tif ". @a ." hsfbu wj"
."suvft pg b qsphsbnnfs"
. ":\n";$c =~y/b-y/a-z/;
print"\n\n$c ";for($i=0;
$i<@a; $i++) { $a[$i] =~
y/b-y/a-z/;if($a[$i]eq$a
[-1]){print"and $a[$i]."
;}else{ print"$a[$i], ";
}}print"\n\t\t--$b\n\n";
 
I agree. It is always good to have a screen full of perl code up on your computer at the office. It makes people avoid you. :)
 
shrill - did you write that obscene perl code in your signoff, or is it one of these things that gets passed around?

What's with the .and .and .and .and .and .and .and .and .and .and .and
 
Actually, it's perl code that comes from a T-shirt that some web site was selling. If you run the code, you get:

The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall


Take it as evidence of what nikuvu said: "Any language can be obfuscated"


(PS: i think the website was www.thinkgeek.com, but I don't see it there anymore)
 
There are lots of unemployed coders out there .

I think open source unix type OS software is going back to normal ( it was kinda hyped up in the late 90s ) , beeing a hobby/student software and not such a big deal .

I enjoy the mental stimulant , and its made me sober beeing a computer student . No more beer chugging contests for me .

I like darwin , its a little different than Free BSD but its a open source unix OS and as long as its not microsoft I am happy .

If you havnt yet check out SuSE PPC Linux .
 
C - You shoot yourself in the foot.
Java - You create a model of a gun that automatically shoots you in the foot.
BASIC - You pick up a marble and throw it at your foot.
Perl - You find an efficient way to shoot yourself repeatedly in the foot with only one bullet.
HTML - You seem to be able to shoot yourself in the foot okay, but you'll need to try it out on different feet just to make sure its compatible with different footwear.
 
Back
Top