3 ms·
An example : for _, a := range albums { if a.ID == id { c.IndentedJSON(http.StatusOK, a) return } } is ugly co
by nassimsoftware 5y ago
An example :
for _, a := range albums {
if a.ID == id {
c.IndentedJSON(http.StatusOK, a)
return
}
}
is ugly compared to a much more readable :
for a in albums:
if a.ID == id:
// the rest of the code
or
albums = append(albums, newAlbum)
is ugly compared to
albums.append(newAlbum)
Edit : I have trouble formatting the code. How do you do this on HN ?` doesn't seem to work.
Edit 2 : Fixed the formatting issue.
- fshee 5y agoSuperficial. You prefer no braces, no underscores, and no colon. Typing is cheap. I don't mind 'em. Your second example has more implied than syntactical gripes. albums = append(albums, newAlbum) implies immutability. I like that. The latter does not. I don't like that. Beauty is in the eye of the beholder.
- stolen_biscuit 5y agoCorrect, they were asked their opinion about why they think it's ugly, they gave it
- fshee 5y agoTrue. I seemed to have missed that and came off a tad rude doing so. Part of my opinion is now in the mix. :-)
- deepsun 5y ago> implies immutability. Except that implication is incorrect -- slices are mutable.
- Someone 5y agohttps://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsfaq.html: What kind of formatting can you use in comments? http://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc: Text after a blank line that is indented by two or more spaces is reproduced verbatim. (This is intended for code.)
- xyzzyz 5y agoYeah, I find the “xs = append(xs, x)”, or for concat, “xs = append(xs, ys...)” supremely ugly. Or, its time module: you can write 3 * time.Second, which is reasonable enough, but when you have a variable instead of constant literal, you need to write time.Duration(x) * time.Second — entire expression represents the time interval of 3 seconds, but the “time.Duration(x)” component of it makes no sense at all in isolation - it’s just horrible API design. Also, its time zone API is atrocious too: it doesn’t distinguish absolute timestamps from local (wall clock) time on the type level. Saddest part is that it’s actually pretty good language at getting things done, you just have to hold your nose and pretend it was invented in early 1980s, before the industry figured out good, clean solutions to many problems, and converged on them. Otherwise, to think that someone thought nil (that is, not empty) arrays, or returning value/error as pair instead of tagged result union, or lack of generics, is a good idea on 2000s, is just unconscionable.