So then, if I’m parsing your viewpoint correctly, “OOP = bad, functional
programming = good, callbacks = bad”?
…huh?
You do know that callbacks (AKA the use of higher-order functions) are one of
the most fundamental aspects of functional programming, don’t you?
Yes, and often it sucks. There is a difference or two though… in most FPLs
callbacks have a context so its a bit better: the callback is a closure, not
just a context-less function (as in C).
Good point. I’m used to using Delphi, where callbacks are usually
implemented as method pointers, which are basically simple closures that
provide an object for context. SDL uses a similar principle for its callbacks,
putting a user-defined data pointer as part of the signature for a callback.
That depends entirely on the complexity of the grammar you’re using. For a
lexer
(tokenizer,) being called one character at a time is perfectly reasonable, if a
bit
slower than optimal, and no stack is required.
It’s only reasonable if the lexer is generated by a tool, which builds
a finite state automaton, or at least an NFA.
OK, you lost me again. Parser generation I can understand, but a lexer is dead
simple to hand-roll. I wrote a lexer just a few weeks ago. It took a couple
hours
to write and about 10 minutes to debug. Weighs in at a bit under 400 lines of
code for the business logic, plus a keyword table. Child’s play.
There’s nothing inherently bad about callbacks.
There’s nothing inherently bad about assembler or using gotos either.
It’s only bad if you this kind of technology when there’s something better.
I assume you’re still talking about C callbacks with no context here? Also, why
do you keep ragging on ASM? The structured programming theorems prove
that you can write any program without gotos, but there are some things that
simply can’t be done without the use of inline assembly, and IMO any language
with no support for it is crippled.
The problem isn’t callbacks (Felix has callbacks! and as you point out
HOF’s often use callbacks). The problem is when you’re forced to use
them by a framework and your problem is complex enough you demand
the tools of higher level systems: modularity, integrated data and control
flow using a stack, and if you go even higher level you need things like
garbage collection for memory management.
Any examples? I’ve never run across a scenario where a framework forces
you to use a callback for a situation that’s not appropriate for one and it ends
up getting in the way.
Also, WRT garbage collection, I’ve never encountered any programming
problem, no matter how “high-level,” that required it. I consider garbage
collection one of the worst misfeatures of all time. It’s only “necessary” in
functional languages because they’re designed very poorly, based on
fundamental principles such as “let’s pretend we’re not really running
on a Turing machine.” The problem with GC is that it eliminates the
perception of the need to think about memory management, without
eliminating the actual need to think about memory management, thus
eliminating quite a bit of thinking that is still necessary. (See
http://tinyurl.com/9ngt74 and http://tinyurl.com/4pxr822 )
Obviously for simple jobs assembler is just fine.
Most (non-arcade) games and GUI applications are complex enough that
callbacks alone just won’t do.
I don’t know. At work I work on the most complex GUI application I’ve ever
seen. It weighs in at around 3.5 million lines of Delphi code, and if you live
in the USA and watch TV or listen to the radio, chances are it’s running your
station. And, being a GUI application, everything that happens gets kicked
off by an event handler, which is a callback with a method pointer.
My point is not that assembler, gotos, procedural code, or OO are bad:
my point is that they’re limited.
And functional programming isn’t? It’s difficult to even look at a serious
functional language like Lisp or Haskell without saying “this entire thing is
one big abstraction inversion!”
And a second point needs to be made: better technology like fibres can’t
be implemented without compiler support.
Sure it can. I just call the CreateFiber function and I’m good.
http://msdn.microsoft.com/en-us/library/ms682402(v=vs.85).aspx
You can’t do block structured programming in assembler
even though you can emulate the principles. You can’t do OO in C,
even though you can emulate it. You can’t do real functional
programming in C++. And you can’t do coroutines
without language support either.
You know what the difference between doing something the “real” way,
with language support, and emulating the principles is? When it’s not
built into the language as a fundamental abstraction, you can debug
it, examine it, and find ways to improve it. When the language abstracts
all that away, you lose that ability.
That’s part of the reason why I like Delphi. You can do extremely high-level
stuff in it, including functional programming with real, language-supported
closures, but you can also go as low as you need to, all the way down to
inline ASM if necessary.
Game programmers are the worst hit by bad technology because games
are the most sophisticated and difficult application around. Which is why
most games are so deficient in many ways … most “so called” strategy games
have hardly any strategy in them, their unit routing algorithms are
non-existent
or suck totally – even though good algorithms exist – because the programmers
spend most of their time struggling to implement basic stuff without error,
because the tools they’re using aren’t up to the job.
Most of that can be laid at the feet of C++. If game programmers were smart,
they’d use a language with a real object model and decent OO semantics, and
half their trouble would vanish.>----- Original Message ----
From: john skaller
Subject: Re: [SDL] text input and key down events
On 23/02/2011, at 1:02 AM, Mason Wheeler wrote: