3 ms·
Sounds cool, but what exactly is the advantage of doing it like that?
by veddox 6y ago
Sounds cool, but what exactly is the advantage of doing it like that?
- Jtsummers 6y agoThere are a couple reasons and ways to use that approach. Unlike batch compiled languages, Smalltalk and Common Lisp (and some others) will throw an exception/signal an error/whatever that indicates that a function doesn't exist. This means that you can insert these calls and, unless they actually occur, the rest of your program runs just fine. In most batch compiled languages you'd at least need to insert a dummy method/function (in C# you'll see NotImplementedException being thrown in these). When you encounter the exception, in languages that support it, you can write the code at that time and then let the system resume, or tell the debugger to return a value. Maybe you don't know how to implement that function, but you know the kind of thing it should return and, for some reason, you don't want to leave function floating out there that just returns a dummy value permanently ((defun random () 4))). If you use a language like Smalltalk, there's also a tendency to write very short methods. You could use this approach to create your program in a more top-down fashion (versus bottom-up) by doing something like this (I don't know Smalltalk so this is lisp): (defun main() (factorial 10)) Debugger is brought up because factorial doesn't exist. (defun factorial (n) (fact-aux n 1)) ;; not really needed in Common Lisp, but just to illustrate Again the debugger is brought up so we define the next function: (defun fact-aux (n acc) (if (<= n 0) acc (fact-aux (1- n) (* n acc))) If you already have a design in mind (sketched out on paper perhaps), you could use something like this pretty effectively. Not sure I would though.
- vindarel 6y agoYou can write tests and then the functions: https://www.youtube.com/watch?v=CNFr7zIfyeM https://www.youtube.com/watch?v=CNFr7zIfyeM and you can interactively fix failing tests: https://peertube.video/videos/watch/c0c82209-feaa-444d-962f-afa25745bfc0 https://peertube.video/videos/watch/c0c82209-feaa-444d-962f-...