Post AUNweutd21t2cBJMki by simon@fedi.simonwillison.net
 (DIR) More posts by simon@fedi.simonwillison.net
 (DIR) Post #AUNtnXoluEmDmZShuq by simon@fedi.simonwillison.net
       2023-04-06T19:07:33Z
       
       0 likes, 0 repeats
       
       Fun GPT-4 use-case: comparing how different languages/frameworks solve common problemsMy prompt:> Show me code examples of different web frameworks in Python and JavaScript and Go illustrating how HTTP routing works - in particular the problem of mapping an incoming HTTP request to some code based on both the URL path and the HTTP verbDon't show installation instructions, just get straight to the code snippets. Don't show installation instructions, just get straight to the code snippets
       
 (DIR) Post #AUNtzF31WDxX2ihpHk by simon@fedi.simonwillison.net
       2023-04-06T19:08:44Z
       
       0 likes, 0 repeats
       
       Here's the resulting transcript. It gave me examples in Flask (Python), Express (Node.js) and Gin (Go) - then on further prompting added more examples for Django (Python), Koa (Node.js) and then Actix-web and Rocket for Rust:https://gist.github.com/simonw/fa2379b97420404a81b0fcdb4db79657
       
 (DIR) Post #AUNuAy4wR2SptCC7hw by simon@fedi.simonwillison.net
       2023-04-06T19:09:44Z
       
       0 likes, 0 repeats
       
       As someone who spends a whole lot of time on API design, this feels like a /really/ useful trick - researching how multiple frameworks across multiple other languages solve a problem is incredibly useful for coming up with a coherent new design
       
 (DIR) Post #AUNuaSWCOl4lXH6CYK by SnoopJ@hachyderm.io
       2023-04-06T19:12:04Z
       
       0 likes, 0 repeats
       
       @simon interesting how the choice of port varies across these samples when not constrained, I guess it's keying off of idiosyncratic preferences from each of the represented communities
       
 (DIR) Post #AUNuwP9ZacexTDyqjw by simon@fedi.simonwillison.net
       2023-04-06T19:20:25Z
       
       0 likes, 0 repeats
       
       Turned this into a quick TIL: https://til.simonwillison.net/gpt3/gpt4-api-design
       
 (DIR) Post #AUNvFIkFdkmp659AzA by jimfl@hachyderm.io
       2023-04-06T19:23:45Z
       
       0 likes, 0 repeats
       
       @simon If you want to see a super clean example, ask for an Elixir/Phoenix example. The power of macros.
       
 (DIR) Post #AUNweutd21t2cBJMki by simon@fedi.simonwillison.net
       2023-04-06T19:39:35Z
       
       0 likes, 0 repeats
       
       @jimfl Neat tip, thanks - added that one to my collection
       
 (DIR) Post #AUNxYZKAQH2pvYGH68 by mikemol@pony.social
       2023-04-06T19:49:27Z
       
       0 likes, 0 repeats
       
       @simon Heh! I imagine RosettaCode.org is now obsolete, then. Makes me kinda happy; it had a good run. But I think GPT is ultimately a better model, since it doesn't require the information source pre-generate and pre-cache all the combinatorial space of task X language X library.
       
 (DIR) Post #AUNy1GqGDcld0FxWbo by mnl@hachyderm.io
       2023-04-06T19:54:41Z
       
       0 likes, 0 repeats
       
       @simon I go really oblique and have been playing with things like “write a coroutine scheduler in bash in the style of Tolkien if he was a Haskell programmer”, works best against the less reinforced apis, and comes up with some really fun patterns. Also, doing things like the galactic pot healer telephone game: api in rust translate to go translate to Haskell and then back to typescript and finally rust, rinse repeat.
       
 (DIR) Post #AUNz0vgsxTpNMFyWGG by anirvan@mastodon.social
       2023-04-06T20:05:50Z
       
       0 likes, 0 repeats
       
       @simon Simon, I learn so much from all the examples and experiment you share. Thank you!
       
 (DIR) Post #AUNzuWSXxFVNJymEyW by frabcus@mastodon.social
       2023-04-06T20:15:47Z
       
       0 likes, 0 repeats
       
       @simon The answers are all disappointingly the same.e.g. I think the system for this should auto-canonicalise this, and consist of the input function from URL ---> dict of view/parameters which matches URLs loosely in a configurable way (e.g. with without /, case insensitive, even spelling variations etc)Then a map from the dict of view/parameters to the definitive output URL. (This would also be used for URL generation)And then the framework automatically redirects to the canonical URL.
       
 (DIR) Post #AUPV8DTfUp3fOCPSWO by joeshaw@mastodon.social
       2023-04-07T13:40:27Z
       
       0 likes, 0 repeats
       
       @simon a possible downside to this, though, is that it isn’t necessarily giving you the best answers and you may not be immersed enough to know. I personally wouldn’t recommend Gin as an example to be emulated, for example.
       
 (DIR) Post #AUPYCKCWjvyZGM2hkW by simon@fedi.simonwillison.net
       2023-04-07T14:11:47Z
       
       0 likes, 0 repeats
       
       @joeshaw that's why I ask for lots of examples - I don't care about which one is "best", I want to see a wide range of different approaches to the same problem
       
 (DIR) Post #AUPYP3G130ZoTek8EC by simon@fedi.simonwillison.net
       2023-04-07T14:13:54Z
       
       0 likes, 0 repeats
       
       What's wrong with Gin? The API design it used there looked pretty clean to me, reminiscent of Express
       
 (DIR) Post #AUQ5BxvAcC2iv8IPmi by joeshaw@mastodon.social
       2023-04-07T20:23:37Z
       
       0 likes, 0 repeats
       
       @simon My main complaint is that it doesn't conform to the standard http.Handler interface, so it makes interoperability with the vast majority of Go HTTP code out there difficult.