4 ms·
I'm trying to wrap my head around "thinking like a language designer" when approaching software dev. It's the viewpoint in this article that I'm intrigued by t
by tom_b 16y ago
I'm trying to wrap my head around "thinking like a language designer" when approaching software dev. It's the viewpoint in this article that I'm intrigued by these days - that building DSLs in Lisp is a source of great expressiveness in coding.
- jerrya 16y agoA trillion years ago, I had to get 50 Lisp machines speaking in an SNA network to American Express' IBM mainframes. The programmers of two companies got our network engineers together, and we designed a protocol to minimize network overhead and still be all robust, fast, reliable, recoverable.... American Express mainframes were available for our use six months down the road, at 2am and for 2 hours. Once a month. They didn't have (or offer us) any sort of testing environment. We went live at 2am for two hours and could debug our code after that offline. At least that was the common Amex procedure. So I wanted to build our half of the protocol, plus a simulator of their half the protocol. What I ended up doing was creating a DSL for describing the finite state machine at the heart of our protocol. Allowing the user (me) to easily specify the parameters of each state and associate them with behavior. Timeouts, transitions, actions to take, error conditions, etc. (def-state ...) Upon doing that my simulator basically fell out trivially, and we could test the network, test our responses, inject errors, all sorts of fun things. It's 2am at Amex and we're going live and many people at Amex dislike our crazy group with our non-IBM machines and they'd love to see us fail. And guess what? It doesn't work. American Express' mainframe code implementation of or protocol is just wrong and not what we agreed to. Eh whatever. It took 30 minutes to confirm there was a problem, another 30 minutes to figure out what the erroneous state implementations were doing, and then instead of going back to cry at our hotel, I just changed our protocol to match theirs, and ... it worked. Not as exciting as saving the Apollo moon landing, but it's my story. So I was able to "think like a language designer", and I created a language very specific to our needs in Lisp. Describe a communications protocol and decorate the states with the constraints and behavior you need. And at 2am, it was very nice to be able to "think like a finite state machine" developer, and just focus directly on re-arranging the states and their transitions and be confident the underlying machinery would deal with the rest. fwiw.