TPJ wrote:I really don't want to start (yet another) rant on the "dynamic vs. static typing" here, so I'll just point my point of view.
I'm coming from static typing world (mainly Java). Although type hints *might* (not: *will*) improve performance, in my opinion they make code more readable.
I respect that you find it more readable. If you do, that's fine. Many others won't, however. Idiomatic Lisp code doesn't use lots of typing. Writing Lisp as it it were Java does not result in readable code for native Lisp speakers. It's like trying to speak a foreign language and
deliberately using your native accent or grammar constructions when you pronounce the foreign words. It just pisses off the native speakers of that language. If you're going to speak a foreign language, at least try to use the correct accent and grammar. Yes, you won't get it down immediately. That's understandable. But it will come over time and people will have more respect for you if they see you trying. Put simply, if you want to sit in your own room and talk French to yourself with a Russian accent, that's fine with everybody because nobody has to hear you, but don't expect the French to think you're doing it right.
Regarding performance, in many cases, the compiler can infer types in any case (see what SBCL does, for instance, and you'll be amazed. It's not perfect, but unless you're in an inner loop, I'm sure you'll find the compiler type inferencing more than enough for your needs. Again, particularly as a newbie.
When I say:
Code: Select all
(defun my-fun (a)
(declare (type fixnum a))
...)
I'm making it clear that "a" is a fixnum number (and not a string, a list, or something else).
Except now my-fun doesn't work (assuming you have a high enough SPEED optimization setting for the compiler to listen to you) with bignums. Or floats. Or any other numeric type. Instead, I would suggest:
Use "lst" or "l" for lists, "arr" for arrays, and "seq" for general sequences, for instance. There is no standard for this sort of thing, but there are several conventions and people will immediately understand it.
My experience from using both static (mainly Java) and dynamic (mainly Python) languages shows, that using such a type hints (let's treat them as hints) allows to write less error-prone and more readable code (at least for me).
That's the main reason why I'm trying to use type hints in CL.
Okay, that's fine. You can do whatever you want. I won't argue with you further. Just realize that anybody else who knows Lisp will look at your code and say "Gak!"
