freenode/#lisp - IRC Chatlog
Search
10:20:43
tempate
Can I get tips to improve this piece of code? https://gist.github.com/Tempate/2a05c584e1b29c9c609c90856c566128
10:27:21
beach
tempate: Your PROGN should be indented 2 spaces, but then, since LET has an implicit PROGN, you don't need it.
10:31:32
beach
It is very low level. Usually, you design a data structure around classes and generic functions. That's known as a "protocol".
10:32:36
beach
Just as you don't want to access fields in a structure or class directly, you typically don't want to access Common Lisp slots directly.
10:41:53
White_Flame
you could add a count to the class to cache the length, so you don't have to recompute it, which would be a fairly easy optimizatin
10:45:31
beach
tempate: Common Lisp classes don't have methods in them. Encapsulation is accomplished with an orthogonal mechanism known as "packages".
10:46:49
White_Flame
(and packages aren't really "encapsulation" because you can always still poke into them; there's no real data hiding in CL, besides closures (and you can use implementation tools to poke into those, too))
10:56:43
White_Flame
just for fun, a verbose single-pass version on a list: https://pastebin.com/TRwCBaHw
10:59:24
tempate
White_Flame: updated to use a counter: https://gist.github.com/Tempate/2a05c584e1b29c9c609c90856c566128
11:00:03
White_Flame
yep, and you see how optimization tends to make things bigger and less independent
11:00:50
White_Flame
if some external code munged your list behind the scenes, the prior version would still work, while this would get confused
11:01:24
White_Flame
for initial development, it's advantageous to have code as clear and flexible as possible, even if it's slow
11:01:35
White_Flame
putting the screws to it to make it faster tends to come after it's settled down
11:32:00
jackdaniel
I think that this bon mot is one of few causes of a very sad state of software today
11:33:28
jackdaniel
not that it doesn't have some truth to it, just that people stick to it even when they absolutely shouldn't