<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc=" http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>briancarper.net (λ) (Tag: C)</title><link>http://briancarper.net/tag/182/c</link><description>Some guy's blog about programming and Linux and cows.</description><item><title>C++, blech</title><link>http://briancarper.net/blog/c-blech</link><guid>http://briancarper.net/blog/c-blech</guid><pubDate>Tue, 01 Apr 2008 22:15:36 -0700</pubDate><description>&lt;p&gt;I decided to try a GUI app.  I decided to use QT4.  I then quickly remembered why I don't ever use C++ for anything.  The amount of bullcrap you have to go through just to get a simple program going isn't worth the bother for the kinds of programs I write.  I spent an hour on this and I haven't even started writing any of the actual program yet.  Just setting up boilerplate garbage, using &lt;code&gt;qmake&lt;/code&gt; to make the project file used to make the Makefile used to compile my program someday if I ever actually progress far enough to write it.  But no, the compiler couldn't find some of Qt's headers, so I get to hunt them down and pray.  Nope, not worth my time.  You know it's a bad sign when you can copy/paste a Qt tutorial right from the Qt docs and it won't compile.&lt;/p&gt;

&lt;p&gt;I've always detested C++.  I thought maybe I'd start liking it more as I learned more about how computers and compilers and interpreters work, but no, actually I like C++ less and less.  I read some books on C++ a while back and it seemed nice at the time, but reading about a language and using it yourself are two very different things.  I find myself disliking statically typed languages in general in ever-increasing amounts.  And languages without garbage collectors seem archaic to me.  And any language that requires you to learn multiple new languages just to be able to configure and use the tools used to build your program is ridiculous.  I have a hard enough time getting my logic right, let alone having to hand-hold the computer while it laboriously and clumsily stumbles through my code.  Ruby and Lisp have spoiled me.&lt;/p&gt;

&lt;p&gt;And God help me if I ever want to run it on someone else's machine.  Or a different OS.  I started looking into how to compile Qt apps in Windows and now I shudder to think what I almost got myself into.  &lt;/p&gt;

&lt;p&gt;Interpreted languages are as close as anyone's going to get to &quot;Write once, run anywhere&quot;.  Step 1: Install Ruby.  Step 2: Write Ruby code.  Step 3: Run it.  Short of places the OS leaks through like pathnames or system calls, your program will work.  End.  Underneath all of that, someone still had to figure out all the low-level crap.  But someone smarter than me figured that out, and had to figure it out ONCE, and then it's done with and I can take advantage.  Worst thing that can happen is I get some missing Ruby files and throw them in a directory somewhere Ruby can find them. &lt;/p&gt;

&lt;p&gt;Programming after all is all about abstraction.  Abstraction layers help us deal with complexity.  Ruby is an abstraction layer over a mess of C code and compiled and linked binaries and libraries that I never have to look at.  That's the way I likes it.&lt;/p&gt;

&lt;p&gt;I was going to use Ruby's QT bindings for this app, but I want it to be multithreaded, which probably rules Ruby right out.  Sad.  Maybe Python has good Qt4 bindings.  Horrifying though the thought of writing Python may be, at least the syntax is more stomach-able than C++.&lt;/p&gt;</description></item><item><title>PAIP, review one of probably many</title><link>http://briancarper.net/blog/paip-review-one-of-probably-many</link><guid>http://briancarper.net/blog/paip-review-one-of-probably-many</guid><pubDate>Wed, 06 Feb 2008 01:12:18 -0800</pubDate><description>&lt;p&gt;I got through the first four chapters of &lt;a href=&quot;http://norvig.com/paip.html&quot;&gt;PAIP&lt;/a&gt; yesterday and today.  It's good so far.  I had reservations about spending $80 on a book, but it's 950 pages and almost all of it is good stuff, from what I can see at a glance.  Little space is wasted on introduction material or tutorials for people who know nothing about programming.  He dives right into the good stuff in chapter four.&lt;/p&gt;

&lt;p&gt;Already I've picked up a few nice bits of info, interesting standard functions / macros like &lt;code&gt;TRACE&lt;/code&gt; which is good for debugging.  And &lt;code&gt;SUBLIS&lt;/code&gt; which takes a list of (key . value) sublists and replaces all the keys with all the values, in some other list.  Common Lisp is such a freaking huge language, in terms of its standard library of functions.  Good thing or bad thing?  It may be a bad thing if not for the fact that you load Lisp once and it persists forever.&lt;/p&gt;

&lt;p&gt;Norvig makes an interesting point about the REPL.  What do most programs need to do?  Take input from the user, do something with it, and give output back to the user.  &lt;/p&gt;

&lt;p&gt;To get input, your program can read from command-line args, or prompt to STDIN, or take it out of text fields in a QT app, or read it from a config file.  But it's generally always strings.  So you get some strings, and then what?  You have to figure out what the strings say, and either turn the strings into something usable or use the strings to figure out what action to perform.  So you may have a dedicated library to parse command-line args and a dispatch table to map them to function calls.  Or you may match the strings against a regex and depending what the strings look like, turn them into your language's representation of an integer or float using some &quot;parseInt&quot; or &quot;parseFloat&quot; functions.  Or if your strings are XML, you may parse them into some big funky XML structure, then access bits of that structure to figure out what to do.&lt;/p&gt;

&lt;p&gt;In Lisp on the other hand, you happen already to have a powerful reader/parser at your disposal: the REPL itself.  It already knows how to read string representations of lists, numbers, pathnames, and many other things, and it can turn them into Lisp objects for you with no effort on your part.  If you were using Ruby or Perl, short of &lt;del&gt;evil&lt;/del&gt; &lt;code&gt;eval&lt;/code&gt;, you wouldn't get anything close to that capability in your program.&lt;/p&gt;

&lt;p&gt;What's more, the REPL knows how to read string representations of Lisp code (new functions and function calls etc.), and evaluate the code and end up with Lisp objects.  It would be like if you wrote a C program which prompted you for input, and the input you gave could be a string representing a new C program that when run would produce a string that contained your input (or produce in-memory C structures your C program could use).  So the main program would call GCC and compile and run your input to get results and use those results as its final input.  Except that still wouldn't be nearly as powerful as what Lisp is doing.&lt;/p&gt;

&lt;p&gt;So if you can figure out how to shape your input into a form that the Lisp reader can read, you're set.  And it so happens sexps are a great representation for a great many things.  Maybe this is part of why Lispers seem to worship the REPL and shun compiling their apps into command-line, standalone executables?  Maybe this is part of what's meant by the oft-quoted-to-death &lt;a href=&quot;http://en.wikipedia.org/wiki/Greenspun%27s_Tenth_Rule&quot;&gt;Greenspun's 10th Rule&lt;/a&gt;?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Much more PAIP to follow.  It should be enjoyable.  There's nothing like a good book.&lt;/p&gt;</description></item><item><title>False</title><link>http://briancarper.net/blog/false</link><guid>http://briancarper.net/blog/false</guid><pubDate>Thu, 13 Dec 2007 19:55:25 -0800</pubDate><description>&lt;p&gt;In Ruby, the only things that are false are &lt;code&gt;nil&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;.  This is a nice change over other languages where other things evaluate to false in boolean tests.  Like C and many others, which considers the integer 0 to be false.  So is 0.0 false?  How about 1e-999999?  Or there's Perl, which also considers an empty string to be false, and auto-casts between numbers and strings, which can make things fun.  And of course Perl has Perlish insanity like &lt;code&gt;0E0&lt;/code&gt;, &quot;zero but true&quot;.&lt;/p&gt;

&lt;p&gt;However all languages pale in comparison with PHP.  They provide these &lt;a href=&quot;http://www.php.net/manual/en/types.comparisons.php&quot;&gt;handy charts&lt;/a&gt; to help you figure out what's true and what's false.  &lt;/p&gt;

&lt;p&gt;That really sums up PHP well.  You have three standard functions (isset, is_null, empty) with completely inconsistent names.  Two equality test operators whose meaning completely changes between PHP versions.  And then a couple of 12x12 grids of crap necessary to figure out how they behave.  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&quot;0&quot; == 0&lt;/code&gt;?  True. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;0 == &quot;&quot;&lt;/code&gt;?  True.  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&quot;0&quot; == &quot;&quot;&lt;/code&gt;?  False...  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;null == array()&lt;/code&gt;?  True....?&lt;/p&gt;

&lt;p&gt;Really makes you appreaciate Ruby.&lt;/p&gt;</description></item><item><title>K&R</title><link>http://briancarper.net/blog/kr</link><guid>http://briancarper.net/blog/kr</guid><pubDate>Wed, 12 Sep 2007 14:07:28 -0700</pubDate><description>&lt;p&gt;I got &lt;a href=&quot;http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)&quot;&gt;K&amp;amp;R&lt;/a&gt; (the ANSI C version) as one of the going-away presents from my current / last job, and I just finished reading it.  &lt;/p&gt;

&lt;p&gt;A lot of what's in the book is sort of review for me now but there were some things I'd never seen before.  For example in the book they like to put function declarations inside other functions instead of globally at the top of the file.  I never even thought to do that, for whatever reason.  I also was unfamiliar with some of the more obscure corners of the C language, like register variables.  Apparently the book was just written when ANSI was becoming / had become standard, so it's also fun to get a small glimpse at how things were before that.  (They looked to be a mess.)&lt;/p&gt;

&lt;p&gt;It's definitely the kind of book I wish I'd have had back in high school when I was just learning to program.  For example the very straightforward explanation of how file handles work in Unix systems is nice and clear and is one of those things that I was wondering about for years in my youth: How is it that I can access stdout, stdin and stderr without doing anything?  Where are those handles coming from?  They seemed to be there like magic, and I never knew if it was always safe to assume that I'd have those available in every programming language I used on every OS I tried, or what.  Likewise, I remember in the vast majority of programs I wrote in high school, I would trip up over I/O buffering.  K&amp;amp;R explains that really well also.&lt;/p&gt;

&lt;p&gt;Things that everyone &quot;just knows&quot; and assume that you also know are the biggest pitfall in learning computers, to me.  Unix / Linux seems chock-full of that kind of crap.  How do you know to try &lt;code&gt;--help&lt;/code&gt; or &lt;code&gt;man&lt;/code&gt; to figure out how to use a command?  How do you know that &lt;code&gt;~&lt;/code&gt; means &quot;home directory&quot;?  How do you know that you start X via &lt;code&gt;startx&lt;/code&gt;?  If you don't know those things, short of asking someone else, it's very hard to discover how to do them.  For people who know how to do it, it's such common knowledge that no one bothers to write it down.  It's a huge leap that people have to make when first learning Linux or programming in general.  A book like K&amp;amp;R is great because it gives you a starting point, and they explain pretty much everything.  &quot;Comprehensive&quot; is probably the word I'm looking for.&lt;/p&gt;

&lt;p&gt;In any case, as a rule, I detest low-level programming, of the &quot;bit-twiddling&quot; form.  But there's obviously a need to know how to do it at times, and I think if I was more in the practice of falling back to C or other low-level languages when the problem at hand demanded it, I would probably be a better programmer.  So I'm glad to try to learn more of it.&lt;/p&gt;</description></item></channel></rss>

