4 ms·
Lucky bunch indeed. I'm 9 months in and still missing map(), flatMap(), let alone more advanced FP. I guess this is a matter of personal preference, but I defin
by unscaled 10y ago
Lucky bunch indeed. I'm 9 months in and still missing map(), flatMap(), let alone more advanced FP.
I guess this is a matter of personal preference, but I definitely consider:
users.filter(_.active).map(_.email)
to be easier to read (and not a pain in the ass to type) than:
emails := make([]string, 0)
for _, u := range users {
if u.active {
emails = append(emails, u.email)
}
}
return email
The first style is more explicit about what you want to do, the second style is more explicit about how you want to do it. Go made imperative vogue again, but for me it feels like a throwback all the way to Turbo Pascal. Sure, the Go compiler is really fast, but Turbo Pascal would beat it hands down - on 20Mhz machines with 1MB of RAM.
- pjmlp 10y ago> Sure, the Go compiler is really fast, but Turbo Pascal would beat it hands down - on 20Mhz machines with 1MB of RAM. With more features (TP 7)!
- nunobrito 10y agoThe second example is vastly more readable in terms of understanding what it is supposed to do. I mention this as neither a programmer on either Scala nor Go. If it is of any relevance, I've been writing code for about 20 years across C, Java, Javascript, PHP and shell scripts. I'm sure other FP developers will roll their eyes to a traditional developer like me but the one-liner you mention is simply not self-explanatory for an outsider when reading it.
- spdionis 10y ago"I've been speaking italian, french and spanish for 20 years. I'm sure people who speak germanic languages will roll their eyes to a traditional latin-languages guy like me, but the german sentence you mention is simply not self-explanatory for an outsider when reading it."
- kaoD 10y agoThe second one is so readable it contains a subtle bug nobody noticed.
- sacheendra 10y agoBut that would be caught by the compiler. The error would be variable not defined.
- deleted 10y ago[deleted]
- gribbly 10y agoWhat 'subtle' bug ? It returns 'email' instead of 'emails' which I assume was a typo, which of course the compiler would complain about, are you claiming that a variable name typo is somehow a 'subtle bug' ? Only other thing I see directly is that 'users' is undefined, but this is a code snippet after all, not a working program.
- kornish 10y agoI think kaoD's point is that more code will always produce more errors, and more code (in the name of "readability") can give more surface area for bugs.
- matt_kantor 10y agoOut of curiosity, what specifically do you find unreadable about the first example?
- jim_d 10y agocompletely agree. There is a certain beauty to the first version that once you've learned the concepts it seems a shame to have to write the second one.