7 ms·
It's elegant right up until you need generics. Then it gets ugly fast.
by TylerE 13y ago
It's elegant right up until you need generics. Then it gets ugly fast.
- mitchellh 13y agoI agree you with you about generics, but downvoted you anyways, because "it gets ugly fast" is not true. I've certainly felt the pain of wanting generics for some data structures, but I've never felt the pain to where I've needed to make specialized structures for more than 2 or 3 types. And it had no real effect on the rest of my code. It was just one of those things where if I had generics, I could remove the 3x duplication of some code. It definitely doesn't ruin the language.
- khyryk 13y agoI want map (the function). I want filter. And I don't want to keep rewriting them over and over when I work on projects. They're not required -- indeed, I get by without them --, but the topic of the OP is elegance.
- mediocregopher 13y agoI wrote this to scratch an itch of mine: There is nothing about go which prevents the use of generics. I wrote the following library to scratch an itch of mine: https://github.com/mediocregopher/seq https://github.com/mediocregopher/seq It provides clojure-like data-structures and functions for interacting with them (like map and filter). It's completely immutable and generic, and supports lazy operations.
- steveklabnik 13y agoYes, if you totally throw away the type information, then Go will let you write some generic code. Your library uses a _ton_ of `interface{}`, because it has to.
- TylerE 13y agoPrecisely. Other languages, Nimrod for instance (http://nimrod-lang.org/system.html#515 http://nimrod-lang.org/system.html#515) can manage this while still keeping a simple core, including lots of type-inference. Having generics doesn't automatically turn your language into Java. The map operator in Nimrod has a definition that is clear and simple: proc map[T](data: var openarray[T]; op: proc (x: var T): S): seq[S]
- sdegutis 13y agoOne of the main jobs of a programming language is to reduce the amount of duplication you have to write. It just seems to me like being okay with that is antithetical to progress in practical language development.
- AnimalMuppet 13y agoThat's not what Go thinks its job is at all. Go thinks its job is to make it easier to write and maintain large scale software applications. Removing the amount of duplication that any one developer has to write is not one of the design criteria. If you're not running into the issues that Go is trying to solve, you don't understand why its solutions are at least somewhat interesting, nor why its trade-offs are reasonable.
- copergi 13y ago>Go thinks its job is to make it easier to write and maintain large scale software applications It thinks wrong. Making people duplicate code makes it harder to write and maintain large scale software applications.
- mavdi 13y agoPlease throw this Java mentality away. Code duplication isn't an issue, code maintenance is. While lack of duplication might help, it is in no way a necessity for a maintainable code base.
- iopq 13y agoIf code is duplicate of some other code maintenance increases 2x. If it's in ten places, it's 10x. If two different version diverge and they should really be the same (but for some reason one has data packed into an array and the other has multiple arguments, etc.) it becomes impossible to fix it without breaking something
- coldtea 13y ago>Please throw this Java mentality away. Code duplication isn't an issue, code maintenance is. Actually what you describe is the Java mentality exactly! That's why Java is full of code duplication and is supposed to help with code maintenance.
- yohanatan 13y agoAny language which prevents you from removing '3x duplication of some code' is ruined.
- mjolk 13y agoWhat do you mean? Why do you feel this way?
- anonymoushn 13y agoGo has no generics. You can either rephrase your program to not need them, or pretend that you're using a less-typed language and write code that can blow up at runtime.
- crypto5 13y agoAnd maybe you have a chance to provide simple example of how program can be rephrased in such way that generic will not be needed?
- TylerE 13y agoMany problems need generics to be solved elegantly. Go doesn't have generics. It is completely impossible in Go to write things like user-defined polymorphic container types.
- otterley 13y agoAnd yet, much of the world runs on code developed in languages that don't have them (C etc.)
- TylerE 13y agoYea, it works, in the sense that the bulk of world finance "worked" running on COBOL for 30 years.
- copergi 13y agoAnd look how poorly that worked out. People assume software will break all the time, because most of the software they are exposed to does exactly that. It is 2014. There is no excuse for using languages lacking important features from 1973.
- charlieflowers 13y agoWhat's up with the rampant downvoting the past week or so? I see all kinds of posts downvoted that shouldn't be (like this one). Seems like it has really taken off the past week or so. Downvoting is not something you do merely because you disagree. Valuable, intelligent discussion of complex topics that matter requires some disagreement. Downvoting should be saved for comments that are inappropriate in some manner according to the values of the site.
- deleted 13y ago[deleted]
- jnbiche 13y agoI agree 100%, and I've also noted a clear trend toward rampant downvoting the last 2-3 weeks. I've been here for a number of years and have never noticed or complained about this type of downvoting issue prior to the past few weeks. Do you have any idea why this is happening? There seem to be a handful of people who have recently obtained the ability to downvote, and who are now downvoting any comment that find distasteful -- even ones that are rational and well-thought out. Most of the well-written downvoted comments are eventually upvoted, but these comments are often almost invisible during times of most exposure. I've actually wanted to try to quantify this, but I can't figure out how to establish the pre-downvoting baseline, particularly since people seem to eventually upvote many of the downvoted comments. Edit: To be clear, I'm not complaining about being downvoted. I've got more than enough karma, even if I cared about that. I'm complaining about lots of other people being downvoted for writing cogent, thoughtful comments. It's not a positive trend.
- abtinf 13y agoDownvoting to express disagreement is appropriate on HN. See pg's comment: https://news.ycombinator.com/item?id=117171 https://news.ycombinator.com/item?id=117171
- jnbiche 13y agoThat's a single comment from pg from the very early days of HN. And that's not how things developed organically. Instead, downvoting comments has been reserved for comments that violate community standards. Here's a more recent comment from pg in which he describes ideal comments, and the collegial atmosphere he's been trying to promote for HN [1]. In my opinion, downvoting a well thought-out comment made in good faith is not very collegial. 1. https://news.ycombinator.com/item?id=7445761 https://news.ycombinator.com/item?id=7445761
- rbanffy 13y agoWhy do you think generics are so important? Why do you think they are missing from Go? Can you point to a good example where Go fails because pf it?
- TylerE 13y agoI think one of the biggest problems is that they make it hard to write good libraries. When libraries cannot easily deal with user types that's just not good. Imagine trying to write an ORM for instance.... in Go you are not given many options...you either have to deal with casting via interface{}, making coding both more verbose and lacking in compiler enforced type-safety, or you force the user to implement your interface on all their types.
- rbanffy 13y agoWhen a language has a different feature set, it's often helpful to approach the problem from a different direction. Not all common design patterns apply to all programming languages and it may be more work than it should to shoehorn a concept into a language where it can't fit.