The type system is there to make pointer arithmetic easier!
(and when you're casting things willy-nilly and the program asplodes at run time, well, we know whose fault it is.)
The language's fault? OH BURN
(To be totally honest, I kind of enjoy C. You just have to not come into it with any expectation of anything making any kind of type-theoretical sense at all, and then you'll be fine.)
You get to keep both pieces! :)
2010-06-01 02:17 am (UTC)
Re: Drive by 1990s-ing
Except that happened, by and large! Look out the window and see all the Pythonistas and Rubyfolk with hip haircuts and fixed-gear bikes!
I once got called a hipster for using TextMate.
2010-06-01 08:03 am (UTC)
Re: Drive by 1990s-ing
Judging static typing by C is about as fair as judging macros by C. Haskell and ML are where it's at.
I await Lindsey's discover of C macros. 'macros'
2010-06-02 04:40 am (UTC)
Re: Drive by 1990s-ing
Ah, remember them now but didn't recall them. Probably sidetracked by thinking of pointers as basic, too, so figured you were learning C now. Template metaprogramming before pointers? o_O
Yes. See, template metaprogramming makes sense.
2010-06-01 03:07 am (UTC)
it took me a minute but that was a good pun
Sometimes I forget how many roads there are to being a software geek; I was working with C long enough ago that it never occurred to me that you could be doing the work you're doing, working with the people you're working with, without
some C legs. And yet, you are, and the textbooks by Tanenbaum and Aho, Hopcroft & Ullman that have been sitting on the bookshelf next to me for the last decade1
1. I can talk about stuff in terms of "decade" now. Geez I'm old.
2010-06-01 04:48 am (UTC)
Re: it took me a minute but that was a good pun
The trick is to learn the exotic languages first. Then folks just assume you know the usual ones.
Edited at 2010-06-01 05:06 am (UTC)
That's probably the right way to think of it. Then "int" or whatever just becomes a mnemonic.
I realized yesterday that for a long time I'd been thinking of pointers as boxes that hold things, but that I should really be thinking of them as differently-sized frames that slide around over data. With a box, you just open it by...opening it, but the way you dereference a pointer depends on what it's pointing to.
Edited at 2010-06-01 04:58 am (UTC)
I should really be thinking of them as differently-sized frames that slide around over data
This matches how I think of C and C++ pointers after several chilling years of programming in those languages.
Good! If I'm thinking like you, then I'm doing something right!
You don't even need to get into pointers to wonder why they even bother calling it a type system.
It's terrifying to look up and realize that I've become a function-pointer-syntax apologist. I keep trying to remind myself that "beautifully tricksy in a strangely symmetric way" does not equal "good".
According to that article, strict aliasing both enables and interferes with loop optimization. Seems hard to even tell if you'd want it in a given situation.
P.S. sekrit backchannel bug report!: I had this problem
this morning (even on Ubuntu 10.04 LTS). (But it went away. If it happens again, I'll see if I can add a useful comment.)
You're the only person I know who still uses livejournal, so I didn't see this.
Next you should try assembler. It's just C without functions.
actually, I wrote a thing
that imports everyone's LJ feeds and even makes a second feed for their non-public entries, and sorts them into folders a little bit.
so now that I've done that, I never visit LJ.
and now I never visit google reader either, because it's too overwhelming.
basically I only read twitter.
Twitter is too overwhelming for me. LiveJournal is the only thing that isn't overwhelming.
I find it most helpful to think about pointers as boxes containing arrows. Arrows to where varies, and god help you if your box is labeled "arrow to cookies" and the arrow actually ends in dirty diapers (Prof. Kuenning had a very small child at the time of that memorable lecture.). Of course, sometimes you're looking at a perfectly good number and just interpreting it as an arrow, or you've got this arrow that looks like 712342344 if you squint right.
Subtle thing that causes tricksy and evil bugs if you're coming from a language that's not older than me: "int* a, b;" defines one pointer-to-int and one int. Every other language (other than C++, because C++ stuck too closely to C) gets it right and makes "*" a modifier of "int", but in C it's a modifier of "a". It's for the same reason that the freeway onramps on the 110 are horrible: if there's no prior art, you don't have any bad examples to avoid.
Pointer-to-void is fully as evil as you think it is. It's also the only way to get large swathes of anything done in C. C is beautifully brain-breaking that way. Overall C is typed about as strongly as Perl is typed, but in a differently broken way.
If you spend any amount of time in C / C++, you will want to know a good debugger. gdb may (sadly) still be state of the art. Sorry.
The "int* a, b;" silliness gets warned against so frequently and so vehemently, I can't believe anyone still actually writes it. I don't think I've encountered it in code that wasn't example-of-what-not-to-do code.
I dunno; I like the frame idea better than the box idea for pointers, probably because my box-and-arrow metaphor is already in use.
I occasionally still write it, despite knowing better. It fits my mental model so well that it's an easy mistake to make and a hard mistake to see. On the plus side, I think modern lint systems will warn about it.