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

Is learning C really a must for a programmer?

Name: Anonymous 2012-09-02 6:17

Many have this opinion. Somehow, by doing manual memory management allocation and garbage mangement one would become a better programmer.

I have little experience in C mainly because I can write terser and more readable code in Racket or Haskell. However I'm willing to give C a try just to learn these lessons that everybody keeps talking.

But I have a sneaking suspicion that I already know most of what is there to know. Can you list some useful lessons that a typical high level code dweller would be oblivious of?

Name: Anonymous 2012-09-05 0:40

BLISS is much better than C for low-level programming. It makes interacting with assembly instructions and registers easier. The programmer has complete control over structures, calling conventions and pointers. There are bitfield selectors on every value instead of having to use shift/mask. It has exceptions and error handling, unlike C which leaves everything undefined. It also has a powerful macro system with expression evaluation, local identifiers, recursion, string/number/symbol conversions, and the ability to create new macros and identifiers at compile time. Structures are parameterized and can have user-defined accessing algorithms (like C++'s operator[]). For example, you could add bounds-checking for debug mode, or access a rope or linked list by index. It's more like an high-level expression-based macro assembler. It also has everything C has except for passing structs by value, a floating point math library, programmers, and compilers.
http://trailing-edge.com/pdf/dec/pdp10/TOPS10_softwareNotebooks/vol07/AA_H275C-TK_BLISS_Language_Guide_Apr83.pdf
http://bitsavers.org/pdf/dec/bliss/EY-AY008-SP-001_BLISS_Primer_Volume_2_1979.pdf
http://www.cs.arizona.edu/classes/cs520/spring12/bliss.pdf
http://www.fh-jena.de/~kleine/history/languages/VAX-11_Bliss-32_UsersGuide.pdf

Name: Anonymous 2012-09-05 0:42

>>81
Except that Bliss has no users so it's basically totally unproven.

Name: Anonymous 2012-09-05 0:49

>>69
I assume by hard, you mean you don't know how to do it.
I.e. GCC is not portable, compared to JVM.

Name: Anonymous 2012-09-05 0:58

>>83
How would GCC be less portable than the JVM when the JVM requires a C++ compiler?

Name: Anonymous 2012-09-05 1:02

>>84
JVM requires byte code compiler.

Name: Anonymous 2012-09-05 1:06

>>85
The JVM is a byte code compiler, it is written in C++.

Name: Anonymous 2012-09-05 1:10

The dynamic vs static debate is kinda pointless. Usually, the use cases where dynamic allocation makes sense usually won't make sense to use static allocation and vice versa. For the two extremes: Media editing applications have to expect handling arbitrary amounts of information but the application can be installed on arbitrarily specced hardware to handle the job. Traditional critical control systems handle fixed sized arrays of numbers with filters, transforms and heuristics applied over it, strings shouldn't even come into the equation here except for a string table, and the software is tailored to specific hardware.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2012-09-05 4:47

>>68
They tend to pass the whole object as a copy, because the syntax for that is identical to Java's "pass the reference to the object". Only when the realise they need to actually change the object do they (in a somewhat confused state) start putting &s in.

>>78
If I had to write a program to do this I would probably dynamically allocate once, once the number is known. Otherwise... head -n 1 <yourfileshere> | sort | uniq

Name: Anonymous 2012-09-05 5:35

>>66
A common tool used in these environments is a "memory pool", basically a statically allocated chunk of memory that you can allocate and destroy (usually) fixed-size objects within.
This is still dynamic allocation. You might even unknowingly have used a malloc implementation that had a static limit. When the pool is empty you've got an error. Static memory allocation means that all computations are bounded in space. There's no recursion and no variable sized objects (where do you store references to the fixed-size object, in another fixed-size object?). This works fine for a lot of data crunshing where you can work with an independent subset at a time and applications where the dimension of data vectors in the domain are obviously smaller than an suitably chosen number. Sometimes it's also okay to truncate strings that are too long.

Creating your own tailor made custom allocator that returns (usually) fixed-size ranges from a static word_t pool[POOL_SIZE]; doesn't mean you're suddenly allocating objects statically. Yes, you've gotten rid of fragmentation since your allocator knows that every allocation is equally big, and that's an advantage  malloc doesn't have. Who'd have thought that optimizing for the special case wins over a general case implementation?

I know, let's all just allocate cons pairs (they're fixed size) and then we can build arbitrarily long vectors and strings by chaining them togehter. It's all statically allocated!

Name: Anonymous 2012-09-05 9:53

>>78
See >>87. If the strings need to persist outside of the function, then some form of dynamic allocation will be useful. But if you are only printing them out in sorted order for example, all of the strings can be allocated with alloca. Furthermore, if it is possible to anticpate the lengths of the strings and their quantity, it is possible for one function to allocate a memory workspace with alloca and then pass pointers to the workspace down to the child functions. The point here is that dynamic allocation isn't always necessary, and there are alternatives that will sometimes give you better performance and memory use. If you are not aware of these alternatives, then you are condemned to writing programs that use more memory or more time than necessary.

>>89
Allocation in a memory pool can always be performed in O(1) time using the same short and deterministic sequence of instructions. The same cannot necessarily be said of your favorite malloc implementation. Malloc's interface is more general and this forces its implementation to be more complex. Malloc doesn't know that you might be allocating and deallocating 1 million objects each of size 36 bytes, several times a second. But you do know this, and you can design a more efficient way to get this memory.

Name: Anonymous 2012-09-05 10:02

>>89
>Who'd have thought that optimizing for the special case wins over a general case implementation?

If the special case is all that is necessary then it is foolish to use the general implementation.

Name: Anonymous 2012-09-05 10:08

>>89
Allocation in a memory pool can always be performed in O(1) time
This is correct. But hard time requirements is not always the only problem with dynamic allocation. Dynamic allocation (even if it's from a memory pool of constant size chunks) is dynamic, i.e. performed at run-time and it can fail. Static allocation is perfomed at compile time and the bounds are known in advance. A memory pool is not static allocation.

Name: Anonymous 2012-09-05 11:18

>>40
Of course you need to malloc at least once (or you might need to malloc more than once to find out how much you need to malloc if the stack is not enough for that task) to get big memory on the heap, I mean if that's what you need.

But I guess this only will teach you how shitty the von neumann architecture is and then how shitty (presumably)linux handles your memory on the heap. That's not really programming in the purest sense in my opinion, although it is valuable to realize the sorry state of "cutting-edge" computing.

Basically, learn C if you need to know how shitty computing is today, all the nasty mistakes are there for you to see.

Name: Anonymous 2012-09-05 11:32

>>93
If only Intel stuck with the iAPX432 instead of making the 8086, computing might have been 40 years ahead of the 70's instead of 70's technology with more RAM and a faster speed.

Name: Anonymous 2012-09-05 12:24

>>94

An ubiquitous object model would qualify as the wheel of information technology, the greatest invention of our time, at least in my book.

Name: Anonymous 2012-09-05 12:57

Using memory pools and custom allocators is standard practice in c++. See Boost.Pool. No wonder your c programs are so shitty and slow.

Name: Anonymous 2012-09-05 13:06

>>61
C is nothing at all like assembly. Please stop making this comparison. It is only as portable as are its implementations, none of which btw use more than a small subset of the instruction set without being begged. Fioc could also be compiled and diassembled...that doesn't make it cat all similar to asm programming.

Name: Anonymous 2012-09-05 13:56

>>94
Ultimate CISC

>>95
What do you mean? Objects are not information. There are many good data-interchange formats already. What else do you need but lists, maps, strings and integers?

Name: Anonymous 2012-09-05 17:41

>>100
Nice dubs.

Name: Anonymous 2012-09-05 17:42

thanks!

Name: Anonymous 2012-09-05 18:25

What else do you need but lists, maps, strings and integers?
trees, booleans, floating point numbers, rational numbers, complex numbers, vectors, matrices, functions...

Name: Anonymous 2012-09-05 18:40

>>101
You could implement trees quite trivially with a map.

Name: Anonymous 2012-09-05 18:41

>>102
You could implement maps quite trivially with a tree.

Name: Anonymous 2012-09-05 20:52

>>103
A slow map.

Name: Anonymous 2012-09-05 21:59

Map my anus.

Name: Anonymous 2012-09-05 22:12

>>105
*MAP MY ANUS

Name: Anonymous 2012-09-05 23:23

<map> is rb-tree, isn't she?

Name: Anonymous 2012-09-05 23:48

Learning C is like learning to handle liquor.

Name: Anonymous 2012-09-05 23:58

no, but learning Newspeak is

Name: Anonymous 2012-09-06 4:23

>>108

A useless penis measuring contest?

Name: Anonymous 2012-09-06 5:39

http://www.youtube.com/watch?v=ObP3KIZa8zA

the cover is fucking perfect!

Name: Anonymous 2012-09-06 8:33

>>111
chiptuned trips <3

Name: Anonymous 2012-09-06 8:56

>>111
I guess this is listenable if you're completely oblivious to the so called ``chiptune'' genre, however this is really terrible and you should honestly feel bad for liking it.

Makes me wanna puke, the fact that people who post such things invariably have the most awful taste.

Name: Anonymous 2012-09-06 10:13

>>113
Back to reddit, hipster piece of shit.

Name: Anonymous 2012-09-06 10:15

>>98

Well that's like bits and pieces of rubber and steel in an envelope handed to me, when I wanted a wheel. It would take too long time to put it back together. If you on the other hand knew about the properties and interfaces of a wheel, you'd just hand it to me, not dismantling it first. We'd speak the same language and understand each other living in the same world, on the same terms. Things would be a smooth ride.

Name: Anonymous 2012-09-06 10:20

>>115
no

Name: Anonymous 2012-09-06 10:22

>>116
No, yes.

Name: Anonymous 2012-09-06 10:44

It doesn't have to be C, but a language that is lower-level than your Ruby would be good to learn and prevents you from becoming like the average Rails hipsterfaggot.

Name: Anonymous 2012-09-06 10:46

>>117
no

Name: Anonymous 2012-09-06 11:44

>>119
no

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