libera/#commonlisp - IRC Chatlog
Search
15:16:19
nij-
jhiltu Yeah. alphapapa told me that the point of macros is to abstract syntactically. One lesson I learned from this is to first write codes in functions, and if you spot repeating codes, abstract them in macros.
15:24:56
NotThatRPG
nij-: It's a subtle issue to decide whether to abstract using a macro or a function...
15:28:22
younder
A macro is substituted in directly so it is faster. Of course you could make the function inline..
15:31:36
bike
macros are nice when you actually want new syntax. for example, dolist and mapc do the same thing, and either could be implemented in terms of the other, but it's sometimes nice to just have a body right there
15:33:44
younder
Optimizing compilers like Java's use aggressive function expansion and then register intimation. It is provably best to lave it to the compiler. But yes
15:36:26
NotThatRPG_
younder: Right, but remember that macros can't be invoked with funcall or apply
15:37:13
bike
using macros instead of functions is "for speed" an 80s C move that we don't need to promulgate
15:40:54
younder
If done 'manually' it reads to unreadable code. If done mechanically you get java bloat but better speed.
15:47:45
younder
It is the compiler that should use inlining preferably automatically. The writer should focus on clear code. Macros obfuscate code. Fine for DRY and for creating higher level structures over tagbody if and the like.
15:55:46
NotThatRPG_
Macros like the with- constructs (e.g., with-open-file) reduce bloat and clarify the meaning of code, because you don't have to go hunting around to figure out when resources are cleaned up.
15:56:55
NotThatRPG_
They are also a good reason for macros because you are syntactically abstracting when you splice your resource variable name into the construct.
15:56:58
phadthai
I agree, macros can make code cleaner or messier, but for compiling optimization is where they risk making the code less readable indeed
15:58:28
NotThatRPG_
Keeping in focus the distinction b/w syntactic and semantic abstraction is key.
15:59:39
beach
What bike said: "using macros instead of functions is "for speed" an 80s C move that we don't need to promulgate" + modification
16:00:41
nij-
Oh..? Using macros was for speed mostly only for C (or did I misunderstood)? How come?
16:10:35
bike
it is very common to see C code that does things like "#define MIN(x, y) (x < y) ? x : y" instead of using the standard min function either because it is very old, or because it is new but the person who wrote it is unaware that compilers have improved since 1972.
16:16:54
beach
bike: Exactly. And in the case of some of my former students, it was a general lack of knowledge about how compilers work and what they are capable of. So they would just repeat what they had seen.
16:17:39
beach
This is why I keep repeating that good programmers must know about compiler design and computer architecture.
16:19:54
beach
Another habit my former students had was to avoid variable definitions in inner scopes, particularly in loops, believing that the program would then have to somehow create those variables each time the inner scope was entered.
16:30:03
bike
bad for readability plus makes the register allocator work harder to avoid spills. very nice
19:35:31
nij-
Dyomkin released a book on lisp and data structure.. and faded away. Their rutils is great, but seems unmaintained for a few years.
19:36:35
nij-
Oh.. they're from Kyiv .. https://vseloved.github.io/ Perhaps that explains. Hope they are doing well......