On 11/08/18 16:11, Bob Heffernan wrote: > Dear all, > > I am new to Racket and only slightly less new to scheme & scheme-like > languages. > > I have noticed myself often doing something like the following: > > (define (foo x) > (let* ([y (f x)] > [z (g y)] > [p (h z)]) > (bar p))) I really, really don't like nesting and a few years ago adopted the style of internal defines. It makes for much more readable code: (define (foo x) (define y (f x)) (define z (g y)) (define p (h z)) (bar p)) I avoid nesting, long lines and short names. So I would try to name the variables appropriatelly. If intermediate variables don't have a 'meaning' such that they can be given proper names, maybe they don't deserve to be a variable and instead I will compose. Just my 2 cents. Paulo Matos > > Which could, of course, be written as > > (define (foo x) > (bar (h (g (f x))))) > > Here's an example from something I was just working on: > > (define (get-data input) > (let* ([url-string (construct-url input)] > [url (string->url url-string)] > [port (get-pure-port url)]) > (read-json port))) > > which, again, could be written as: > (define (get-data input) > (read-json (get-pure-port (string->url (construct-url input))))) > > My question is: is the way I'm writing things considered to be bad > style? It feels like a hangover from more imperative-style programming > & the inclination to do one thing "per line". On the other hand, it > often helps readability. > > It might be, of course, that both versions amount to the same thing > after the interpreter has been at them. > > Thanks and regards, > Bob Heffernan > -- Paulo Matos -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Question about style
'Paulo Matos' via Racket Users Thu, 16 Aug 2018 02:44:13 -0700
- [racket-users] Question about style Bob Heffernan
- [racket-users] Re: Question about styl... Wolfgang Hukriede
- Re: [racket-users] Re: Question ab... Shu-Hung You
- Re: [racket-users] Question about styl... Deren Dohoda
- [racket-users] Re: Question about styl... Andrew J
- [racket-users] Searching for packa... Stefan Schmiedl
- Re: [racket-users] Searching f... Daniel Prager
- Re: [racket-users] Question about styl... Greg Hendershott
- Re: [racket-users] Question about styl... 'Paulo Matos' via Racket Users
- Re: [racket-users] Question about ... Robert Girault
- Re: [racket-users] Question ab... Matthias Felleisen
- Re: [racket-users] Questio... Robert Girault
- Re: [racket-users] Questio... Deren Dohoda
- Re: [racket-users] Qu... Hendrik Boom
- Re: [racket-users] Questio... Greg Hendershott
- Re: [racket-users] Qu... Philip McGrath
- Re: [racket-users] Question about ... Bob Heffernan
- Re: [racket-users] Question ab... Neil Van Dyke