Sorry, but I couldn't resist, I'm pretending that someone asked me those questions...
Programming FAQ by edw519
What editor do you use?
Textpad.
How can I learn to program?
Find a customer with unreasonable deadlines. Hit them. Repeat. It won't be pretty, but you'll be the kind of programmer I'd go into battle with: great at the things that really matter and mediocre at the things that don't.
Why do you advise plunging right into a programming project instead of carefully planning it first?
It's incredibly difficult for anyone to define what they want when they start with nothing. It's human nature (incredibly easy) to criticize what you have and how to make it better. Plunging right in and producing anything raises you from LevelIncrediblyDifficlut to LevelHumanNature.
Why do you keep going on about PICK?
I have a very small back pocket that holds everything you need to program in PICK. Whatever you can do in technology <x>, I can probably do in PICK, often quicker and easier.
Isn't object-oriented programming naturally suited to some problems?
Sure, but that doesn't necessarily mean you have to use formal object-oriented technology. You can mimic the concepts with almost any technology.
Find a customer with unreasonable deadlines. Hit them. Repeat. It won't be pretty, but you'll be the kind of programmer I'd go into battle with: great at the things that really matter and mediocre at the things that don't.
If someone never programmed before, and had little concept of programming fundamentals, then I would highly recommend starting with my favourite simple language: Logo.
The thing about logo is that it was specifically designed as an educational language. It teaches the basics of syntax, commands, variables, and functions, and it offers instant gratification. It is very easy to see how a computer can follow very simple programs, and if you do something wrong you see it immediately. Once they've mastered the fundamentals of logo (which should only take a couple hours) then I would have them move on to a full blown language.
I haven't programmed in Logo in years, but I recall it as pretty full-blown: isn't it a dialect of Lisp (with a funny infix syntax but) including macros?
Yes it is, but as far as I know its not widely used outside of the turtle programs. In my opinion, instead of delving deeper into it, the student would probably benefit a bit more in the longrun by spending the bulk of their time on something more mainstream...this would open them to a much more available set of documentation, support, communities, etc. Though maybe I am wrong and there is a thriving massive Logo development community!
I've often thought it would be cool to port LOGO to an AVR or other microcontroller so you could build an "actual" mechanical turtle that would move around the floor in response to the commands. NoteToSelf("Add LOGO to project list");
Someone, somewhere has to have done this already. I should look it up!!
>But if I were trying to solve the problem one reader sent to me as a canonical example of an OO problem, I wouldn't.
Suppose you have n serial ports, each of which may speak one of k protocols, and this must be configurable at run-time.
I'd just use an n-by-k array of closures to represent this.
Can anyone enlighten me about this? My first thought is that n+k units of code is less than n*k, but I expect it's more subtle than that :-)
What about code reuse? In OO land, it's fairly obvious to me that I could take any number of my protocols and use them across a TCP/IP connection, or carrier pigeon, or a file, but I can't see how the closure example would allow this sort of sharing. Is that the point? Only code what's necessary?
Not specific to your issue, but rather to the use of closures where OO folks would use objects.
The thing is, a lot of the time you need sideband data. A simple closure isn't always enough. Perhaps you need configuration options, or you need names for diagnostics, or you need to monitor throughput statistics, etc. A closure is a clumsy interface when it's overloaded to do multiple things. You end up with some kind of variadic argument list and having to switch on the first or more arguments - you basically end up writing a method dispatch routine.
So in this specific example, I would suggest that using a closure may turn out to be the wrong choice longer-term. I'd probably prefer a base class with a virtual method, and a concrete descendant which delegated the action to a closure. That way you get the succinctness of a closure when that's sufficient, but you also get the future proofness that a base class provides - you can add more functionality in the future, but without breaking previously defined implementations.
I ran into a similar problem this morning-- using python tho. There is an api with multiple decorators possible. One decorator has implications for the program execution model. Because python decorators take heavy advantage of closures, we run into a problem where external code cannot determine appropriate actions unless the decorator in question is the outermost decorator. This of course is an ugly requirement.
Our ultimate solution was to create a global table about if the relevant bit of state applies to the function (based on __name__). Also an ugly hack, but keeps the api clean. :(
I suspect the n-by-k array part is a typo, an one-dimensional array of closures is all you need. I also don't think the closure approach is bad for code reuse. The closures serve just to bind the environment to the TCP-handler and UDP-handler functions. The closures themselves are probably trivial and not worth sharing, and the protocol handler functions (or closures) can be shared like any other library function.
Using vi to edit lisp is an interesting choice - I've got the vi commands hardwired in my brain now after using them for 20+ years and I've written a lot of Lisp but I don't think I've ever written any Lisp in vi.
I used vim for lisp for some time. That worked fine actually.
Of course I didn't do things like emacs-slime, so, I always have a repl open in a separate window. ':set lisp' along with 'set lispwords=...' worked fine.
If you have never programmed before, I'd recommend you to start with html, then css, then javascript, then javascript on the server, then sql, then stop. Go back to the beginning and master every one of them.
Then in your spare time learn lisp.
The formers will give you money; the latter, enlightenment.
Forgive me if I'm reading this wrong but it seems to assume someone is trying to learn how to program for the web.
...if you were interested in programming embedded microcontrollers for robots, html and css isn't going to get you too far and I think learning Javascript as your first "programming" language would do more harm than good...
Wait, is there any other programming besides web programming?
For 20 years I've been coding for mainframes, minis and desktops. No more, for the last ten years it all has been the web and solely the web. And I hope it stays like that.
Regarding embedded programming, yeah you're right, but that's a totally different ballgame and I know most of the readers are interested in web stuff.
About old-fart c++ desktop programmers, poor guys, whether they adapt or join the cobol programmers of last century.
Or at least try Go, the language, to keep the fun alive.
As you learn the mechanics of writing and running a program, start thinking about specific programs you want to write.
This is what I never managed. I picked up programming very fast at school, but could never come up with anything I'd want to use it for. Now that I finally have a few concepts I want to see done (good UIs to promising algorithms), I no longer have the time to pursue them.
That's part of why I believe kids now should start with html+js+css and be introduced to greasemonkey, stylish, and browser extensions. Maybe Node.js, too. Everyone uses some site a lot, and they will find problems in those sites to attack with their new knowledge.
It keeps hitting me as a contradiction these two suggestions, namely: a) that you have to understand design to be a good hacker; and b) that planning is overrated.
How can you get to a good design without some plan? Could someone shed some light?
> you have to understand design to be a good hacker
If PG means graphical design, I don't think this is true. Looking at the list of hackers in Coders At Work (as a random sample of respected programmers), it is not clear if any of them understands graphical design and they typically have ugly homepages.
(Jamie Zawinski, Brad Fitzpatrick, Douglas Crockford, Brendan Eich, Joshua Bloch, Joe Armstrong, Simon Peyton Jones, Peter Norvig, Guy Steele, Dan Ingalls, L Peter Deutsch, Ken Thompson, Fran Allen, Bernie Cosell, Donald Knuth)
This is just my personal opinion -- after TeX and real typesetting, typography on the web is so hideously ugly that when confronted with the prospect of a mostly-text website, a disheartened shrug and some basic HTML just to get the characters on a page is all that can be mustered.
Design in an abstract sense that encompasses both visual and systems design probably includes designing programs (coding) as well. So it doesn't say much.
I always thought of it more like architecture and mathematical formulas. You don't have to be a good graphical designer to know what a good mathematical formula or a bad is. However, for mathematicians, a simple and elegant formula is much better than a complicated formula which requires much more work and gives the same answer.
I think Graham answer what he consider as good design in the link below, you should check it out:
http://paulgraham.com/taste.html
Haskell, for example, seems to me a language that's designed more to write papers about than to hack in. I get the impression that using it would feel like reading a novel written by a literary critic.
After using Haskell for a while, that seems to be partially true. It also seems to me that Haskell is especially well-suited to certain kinds of problems. For example, writing parsers with Parsec is very easy. That may be primarily due to the built-in syntax for monads, which would make that advantage fairly easy to duplicate in Lisp.
Programming FAQ by edw519
What editor do you use?
Textpad.
How can I learn to program?
Find a customer with unreasonable deadlines. Hit them. Repeat. It won't be pretty, but you'll be the kind of programmer I'd go into battle with: great at the things that really matter and mediocre at the things that don't.
Why do you advise plunging right into a programming project instead of carefully planning it first?
It's incredibly difficult for anyone to define what they want when they start with nothing. It's human nature (incredibly easy) to criticize what you have and how to make it better. Plunging right in and producing anything raises you from LevelIncrediblyDifficlut to LevelHumanNature.
Why do you keep going on about PICK?
I have a very small back pocket that holds everything you need to program in PICK. Whatever you can do in technology <x>, I can probably do in PICK, often quicker and easier.
Isn't object-oriented programming naturally suited to some problems?
Sure, but that doesn't necessarily mean you have to use formal object-oriented technology. You can mimic the concepts with almost any technology.