Made a desktop file generator, would like some code suggestions #110
Replies: 1 comment 6 replies
-
Well, let's start by saying that concatenative languages with postfix notation are hard to reason about, and I have been trying to make min more readable over the past few weeks/months. While you could reduce the number of variable you declare, I believe that will make your program even harder to read 🙄 There's nothing wrong in your code, but admittedly it took me a bit to figure out what you were doing, even though it's pretty simple. One of the problem could be that n is meant to be a quotation of two elements, but there's no way to understand that without knowing what the template file looks like. Another problem is that it's often not straightforward to figure out how many values a symbol will use up from the stack. Also, if I understand correctly you are also executing the program on an example quotation, instead I would have expected a parametrized quotation maybe built up from args. You could try splitting the code in more operators to do different things. Also the new operator symbol which allows you to specify a signature for your symbol definitions and also captures input/output values automatically, after validating them. (
symbol make_desktop
(quot :n ==>)
(
template n % :desktop
dir "deskgen_$1.desktop" suffix n % :fn
desktop fn fwrite
)
) ::
;; Creates a desktop file given a quotation containing App and Exec values. Then you could also (although a bit of an overkill in this case but you get the point) define a typeclass to validate n as a quotation of two elements:
...which would let you write the signature of the previous operator like this:
Not a huge help but still... I have been trying to make programs more readable, and the answers seems to be splitting into more operators specifying also a signature, and ideally even making more use of type classes -- although actually all this actually increase the program complexity, variable allocation etc. Any other ideas is welcome of course! Like you, I would like programs to be more readable without diverging too much from the concatenative paradigm... but the two things seem to be opposites 🤣 |
Beta Was this translation helpful? Give feedback.
-
Hello everyone!
I've been playing around with min the last few days, and decided to rewrite a small utility I had originally written in Nim. Unfortunately, the resulting min code feels pretty cumbersome/hard to reason about. I would appreciate any tips/tricks that I could use here, especially any that result in fewer variables being declared. It feels like I'm just missing some sort of core concept or symbol.
Anyway, here's the code!
Where template.desktop looks like
Thanks for taking a look!
Beta Was this translation helpful? Give feedback.
All reactions