Update
This commit is contained in:
parent
ed1a6561bb
commit
940ac8279b
11 changed files with 1717 additions and 1681 deletions
35
c.md
35
c.md
|
@ -4,7 +4,7 @@
|
|||
|
||||
C is an [old](old.md) [low level](low_level.md) structured [statically typed](static_typing.md) [imperative](imperative.md) compiled [programming language](programming_language.md), it is very fast and currently mostly used by [less retarded software](lrs.md). Though by very strict standards it would still be considered [bloated](bloat.md), compared to any mainstream [modern](modern.md) language it is very bullshitless, [KISS](kiss.md) and greatly established and "culturally stable", so it is also the go-to language of the [suckless](suckless.md) community as well as most true experts, for example the [Linux](linux.md) and [OpenBSD](openbsd.md) developers, because of its good, relatively simple design, **uncontested performance**, **wide support**, great number of compilers, level of control and a greatly established and tested status. C is **perhaps the most important language in history**; it influenced, to smaller or greater degree, basically all of the widely used languages today such as [C++](c.md), [Java](java.md), [JavaScript](javascript.md) etc., however it is not a thing of the past -- in the area of low level programming C is still the number one unsurpassed language. C is by no means perfect but it is currently probably the best choice of a programming language (along with [comun](comun.md), of course).
|
||||
|
||||
{ Look up *The Ten Commandments for C Programmers* by Henry Spencer. ~drummyfish }
|
||||
{ Look up *The Ten Commandments for C Programmers* by Henry Spencer. Also the *Write in C* song (parody of *Let it Be*). ~drummyfish }
|
||||
|
||||
It is usually **not considered an easy language to learn** because of its low level nature: it requires good understanding of how a [computer](computer.md) actually works and doesn't prevent the programmer from shooting himself in the foot. Programmer is given full control (and therefore responsibility). There are things considered "tricky" which one must be aware of, such as undefined behavior of certain operators and raw pointers. This is what can discourage a lot of modern "coding monkeys" from choosing C, but it's also what inevitably allows such great performance -- undefined behavior allows the compiler to choose the most efficient implementation. On the other hand, C as a language is pretty simple without [modern](modern.md) bullshit concepts such as [OOP](oop.md), it is not as much hard to learn but rather hard to master, as any other true art.
|
||||
|
||||
|
@ -48,7 +48,7 @@ C is extreme well established, standardized and implemented so there is a great
|
|||
|
||||
- [gcc](gcc.md): The main "big name" that can compile all kinds of languages including C, used by default in many places, very [bloated](bloat.md) and can take long to compile big programs, but is pretty good at [optimizing](optimization.md) the code and generating fast code. Also has number of frontends and can compile for many platforms. Uses GENERIC/GIMPLE [intermediate representation](intermediate_representation.md).
|
||||
- [clang](clang.md): Another big bloated compiler, kind of competes with gcc, is similarly good at optimization etc. Uses [LLVM](llvm.md) intermediate representation.
|
||||
- [tcc](tcc.md): Tiny C compiler, [suckless](suckless.md), orders of magnitude smaller (currently around 25 KLOC) and simpler than gcc and clang, cannot optimize nearly as well as the big compilers so the generated executables can be a bit slower and bigger, however besides its internal simplicity there are many advantages, mainly e.g. fast compilation (claims to be 9 times faster than gcc) and small tcc executable (about 100 kB). Seems to only support x86.
|
||||
- [tcc](tcc.md): Tiny C compiler, [suckless](suckless.md), orders of magnitude smaller (currently around 25 KLOC) and simpler than gcc and clang, doesn't use any intermediate representation, cannot optimize nearly as well as the big compilers so the generated executables can be a bit slower and/or bigger (though sometimes they may be smaller), however besides its internal simplicity there are many advantages, mainly e.g. fast compilation (claims to be 9 times faster than gcc) and small tcc executable (about 100 kB). Seems to only support x86 at the moment.
|
||||
- [scc](scc.md): Another small/suckless C compiler, currently about 30 KLOC.
|
||||
- [DuskCC](duskcc.md): [Dusk OS](duskos.md) C compiler written in [Forth](forth.md), focused on extreme simplicity, probably won't adhere to standards completely.
|
||||
- [8c](8c.md), [8cc](8cc.md), [chibicc](chibicc.md): Some other small compilers.
|
||||
|
@ -57,7 +57,7 @@ C is extreme well established, standardized and implemented so there is a great
|
|||
- [pcc](pcc.md): A very early C compiler that was later developed further to support even the C99 standard.
|
||||
- Borland Turbo C: old proprietary compiler with [IDE](ide.md).
|
||||
- [sdcc](sdcc.md) (small device C compiler): For small 8 bit [microcontrollers](mcu.md).
|
||||
- msvc ([Micro$oft](microsoft.md) visual C++): Badly bloated proprietary C/C++ compiler by a shitty corporation. Avoid.
|
||||
- msvc ([Micro$oft](microsoft.md) visual C++): Badly bloated proprietary C/C++ compiler by a shitty [corporation](corporation.md). Avoid.
|
||||
- ...
|
||||
|
||||
## Standard Library
|
||||
|
@ -71,21 +71,36 @@ The standard library (libc) is a subject of live debate because while its interf
|
|||
- [not using](dependency.md) the standard library :)
|
||||
- ...
|
||||
|
||||
## Bad Things About C
|
||||
## Good And Bad Things About C
|
||||
|
||||
Nothing is [perfect](perfect.md), not even C; it was one of the first relatively higher level languages and even though it has showed to have been designed extremely well, some things didn't age great, or were simply bad from the start. We still prefer this language as usually the best choice, but it's good to be aware of its downsides or smaller issues, if only for the sake of one day designing a better language. Keep in mind all here are just suggestions, they made of course be a subject to counter arguments and further discussion. So, let's go:
|
||||
Firstly let's sum up some of the reasons why C is so good:
|
||||
|
||||
- **C as a language is relatively simple**: Though strictly speaking it's not in the league of most minimal languages like [Forth](forth.md) and [Lisp](lisp.md), C is the next best thing in terms of [minimalism](minimalism.md) and the small amount of bloat it contains is usually somehow justified at least, the language (or its subset) can be implemented in a quite minimal way if one so desires. It employs little [abstraction](abstraction.md). This all helps performance, freedom and encourages many implementations. C's standard library also isn't gigantic, the important parts basically just provide I/O and help with simple things like manipulating strings and memory allocation, so new C implementations aren't burdened by having to implement tons of libraries.
|
||||
- **It is extremely fast and efficient**: Owing to other mentioned points such as good specification, simplicity, lack of bullshit and having a good balance between low and high level attributes, C is known for being possibly the fastest [portable](portability.md) language in existence, also greatly efficient with memory etc.
|
||||
- **C doesn't limit you or hold (tie) your hands**: This is bad for the beginner but great for the expert, most of the times C won't "protect" you from doing anything, even crashing your program -- this kind of freedom is necessary to achieve truly marvelous things, C is like a race car, it doesn't have speed limiters and automatic transmission, nothing that would tie your hands or increase the car weight, it trusts in you being a good driver.
|
||||
- **C is highly standardized**: Many languages have some kind of "online specification", however C is on the next level by literally being officially standardized by the forefront standardizing organizations like ANSI and ISO, by full time paid experts over many years and iterations, so the language is extremely well defined and described, down to saying which exact things are left undefined/unspecified, leaving freedom of implementation that leads to the language's great performance.
|
||||
- **It's extremely well establishes, optimized, stable and time tested, with many tools**: Being among the oldest languages, the language of the old time [hackers](hacking.md) and the language of [Unix](unix.md), maybe the most important piece of software in history, C has been so widely adopted, reimplemented, optimized and tested over and over that it's considered to be among the most essential pieces of software any platform has to have. Everything on the low level is written in C, so you essentially first have to have C to be able to run anything else. Many companies have invested great many resources to making C fast as it benefited them. While other languages come and go, or at least mutate and become something else over time, C stands as one of very few stable things in computer technology. There are also tons and tons of tools that help with C development, various static analyzers, debuggers, code beautifiers etcetc.
|
||||
- **It doesn't have any [modern](modern.md) [bullshit](bullshit.md)**: There is no [OOP](oop.md), [generics](generics.md), [garbage collection](garbage_collection.md), no [package manager](package_manager.md) etc.
|
||||
- **There is a huge number of [compilers](compiler.md)**: While a "[modern](modern.md)" language has some kind of main reference implementation and then maybe one of two alternative implementations, C has dozens (maybe even hundreds) of compilers. You'll find compilers under all the [licenses](license.md), huge ones with many features and great optimizations, small ones that will run on tiny devices, ones that compile very fast, ones that translate C to other languages etcetc.
|
||||
- **It is elitist**: The relatively higher difficulty of learning the language has a nice effect of keeping idiots out of its community, keeping the language less intoxicated by retarded ideas.
|
||||
- **C is close to the [hardware](hw.md), reflecting how computers work**: This has many advantages: firstly efficiency, as code that maps well to hardware is predictable and efficient, lacking [magic](magic.md) in translation. It simplifies implementations, making the language more free. Then also the programmer himself is close to the machine, he has to learn how it works, what it likes and dislikes -- a knowledge every programmer has to have.
|
||||
- **There is a great balance between low and high level (minimalism vs "features")**: C seems to have hit a sweet spot at which it offers just enough high level features for comfortable programming, such as [data types](data_type.md), functions and expressions, while not crossing the line beyond which it would have to pay a high cost for this comfort, i.e. it managed to buy us a lot practically for free. Things like this cannot really be planned well, it takes a genius and intuition to design a language this way, this shows the greatness of the old master programmers.
|
||||
- **It is [old](old.md), written only by white male [hackers](hacking.md), at times when [capitalism](capitalism.md) was weaker**: No [women](woman.md) were probably involved in the development (of course we aren't racists or sexists, it's just a fact that white men are best at programming), the development was largely part of genuine research, at the time when computers weren't mainstream and computer technology wasn't being raped as hard as today. C developers didn't even think of embedding any political message in the language. Times like this will never be repeated.
|
||||
- ...
|
||||
|
||||
Now let's admit that nothing is [perfect](perfect.md), not even C; it was one of the first relatively higher level languages and even though it has showed to have been designed extremely well, some things didn't age great, or were simply bad from the start. We still prefer this language as usually the best choice, but it's good to be aware of its downsides or smaller issues, if only for the sake of one day designing a better language. Keep in mind all here are just suggestions, they made of course be a subject to counter arguments and further discussion. Here are some of the **bad things** about the language:
|
||||
|
||||
- **C specification (the ISO standard) is [proprietary](proprietary.md)** :( The language itself probably can't be copyrighted, nevertheless this may change in the future, and a proprietary specs lowers C's accessibility and moddability (you can't make derivative versions of the spec).
|
||||
- **The specification is also long as fuck** (approx. 500 pages, our of that 163 of the pure language), indicating [bloat](bloat.md)/complexity/obscurity. A good, free language should have a simple definition. It could be simplified a lot by simplifying the language itself as well as dropping some truly legacy considerations (like [BCD](bcd.md) systems?) and removing a lot of undefined behavior.
|
||||
- **Some behavior is weird and has exceptions**, for example a function can return anything, including a `struct`, except for an array. This makes it awkward to e.g. implement vectors which would best be made as arrays but you want functions to return them, so you may do hacks like wrapping them instide a struct just for this.
|
||||
- **Some behavior is weird and has unnecessary exceptions**, for example a function can return anything, including a `struct`, except for an array. This makes it awkward to e.g. implement vectors which would best be made as arrays but you want functions to return them, so you may do hacks like wrapping them inside a struct just for this.
|
||||
- **Some things could be made simpler**, e.g. using [reverse polish](reverse_polish.md) notation for expressions, rather than expressions with brackets and operator precedence, would make implementations much simpler, increasing sucklessness (of course readability is an argument).
|
||||
- **Some things could be dropped entirely** ([enums](enum.md), [bitfields](bitfield.md), possibly also unions etc.), they can be done and imitated in other ways without much hassle.
|
||||
- **The preprocessor isn't exactly elegant**, it has completely different syntax and rules from the main language, not very suckless -- ideally preprocessor uses the same language as the base language.
|
||||
- **The syntax is sucky sometimes**, e.g. case with variable inside it HAS TO be enclosed in curly brackets but other ones don't, data type names may consist of multiple tokens (`long long int` etc.), multiplication uses the same symbol as pointer dereference (`*`), many preprocessor commands need to be on separate lines (makes some one liners impossible), also it's pretty weird that the condition after `if` has to be in brackets etc., it could all be designed better. Keywords also might be better being single chars, like `?` instead of `if` etc. (see [comun](comun.md)). A shorter, natural-language-neutral source code would be probably better. Both line and block comments could be implemented with a single character (e.g. `#` for line comment, ending with a newline or another `#`, `##` for block comment ending with another `##`?).
|
||||
- **Some undefined/unspecified behavior would maybe be better defined/specified** -- undefined behavior isn't bad in general, it is what allows C to be so fast and efficient in the first place, but some of it has shown to be rather cumbersome; for example the unspecified representation of integers, their binary size and behavior of floats leads to a lot of trouble (unknown upper bounds, sizes, undefined behavior of many operators etc.) while practically all computers have settled on using 8 bit bytes, [two's complement](twos_complement.md) and IEEE754 for [floats](float.md) -- this could easily be made a mandatory assumption which would simplify great many things without doing basically any harm. New versions of C actually already settle on two's complement. This doesn't mean C should be shaped to reflect the degenerate "[modern](modern.md)" trends in programming though!
|
||||
- **The syntax is sucky sometimes**, e.g. case with variable inside it HAS TO be enclosed in curly brackets but other ones don't, data type names may consist of multiple tokens (`long long int` etc.), multiplication uses the same symbol as pointer dereference (`*`), many preprocessor commands need to be on separate lines (makes some one liners impossible), also it's pretty weird that the condition after `if` has to be in brackets etc., it could all be designed better. Keywords also might be better being single chars, like `?` instead of `if` etc. (see [comun](comun.md)). A shorter source code that doesn't try to imitate English would be probably better.
|
||||
- **Some undefined/unspecified behavior is probably unnecessary** -- undefined behavior isn't bad in general of course, it is what allows C to be so fast and efficient in the first place, but some of it has shown to be rather cumbersome; for example the unspecified representation of integers, their binary size and behavior of floats leads to a lot of trouble (unknown upper bounds, sizes, dangerous and unpredictable behavior of many operators, difficult testing etc.) while practically all computers have settled on using 8 bit bytes, [two's complement](twos_complement.md) and IEEE754 for [floats](float.md) -- this could easily be made a mandatory assumption which would simplify great many things without doing basically any harm. New versions of C actually already settle on two's complement. This doesn't mean C should be shaped to reflect the degenerate "[modern](modern.md)" trends in programming though!
|
||||
- Some basic things that are part of libraries or extensions, like fixed width types and binary literals and possibly very basic I/O (putchar/readchar), could be part of the language itself rather than provided by libraries.
|
||||
- All that stuff with *.c* and *.h* files is unnecessary, there should just be one file type -- this isn't part of the language per se, but it's part of its culture.
|
||||
- TODO: moar
|
||||
- All that stuff with *.c* and *.h* files is unnecessary, there should just be one file type probably.
|
||||
- ...
|
||||
|
||||
## Basics
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue