6 ms·
Do you have an example of the community celebrating mediocrity? My impression is of a community willing to go without some features, in order to preserve those
by rpercy 10y ago
Do you have an example of the community celebrating mediocrity?
My impression is of a community willing to go without some features, in order to preserve those it values. Namely simplicity, explicitness, terseness, and consistency.
- MichaelGG 10y agoExplicitness and terseness seem a bit at odds - I wouldn't call go code very terse at all. It seems verbose and repetitive. Consistency? Aren't only some built in types blessed with generic functions? Mediocrity? The preference for writing loops over simple maps or folds is a bit mediocre. IIRC in Tim Sweeny's "Next Mainstream Programming Language"[1], he notes that around 90% of all the loops in Unreal are folds or maps. Maps and folds are just simpler than loops, without even appealing to terseness and elegance. Hey I know I'm in no place to judge -- the creators of go and Google overall have accomplished more than I'll ever do. I just really cannot grasp the mindset and penchant for unexpressive languages. 1: http://lambda-the-ultimate.org/node/1277 http://lambda-the-ultimate.org/node/1277
- sidlls 10y agoMaps and folds are implicit loops. For some explicit is simpler.
- mattnewton 10y agoNo, maps are conversions between types containing other types. Maps are much more powerful than just doing something over an array in languages that support a functional style.
- sidlls 10y agoThe original comment was comparing maps and folds to loops, not the general application of maps.
- Scriptor 10y agoMaps are explicit transformations of data. For some, making the business logic explicit is simpler.
- solidsnack9000 10y agoLoops are just implicit goto... The argument for maps and folds is the same as the argument for structured programming in general: using common/reusable idioms brings clarity and familiarity.
- sidlls 10y agoTerseness doesn't necessarily bring clarity.
- solidsnack9000 10y agoIt's the recognizability, not the terseness, that brings clarity. Although Python's approach is not terse -- `fstyle = [f(x) for x in arr]` -- it is eminently recognizable. Your argument is not really about anything I specifically said; and without something to counterbalance, it argues against structured programming, too.
- sidlls 10y agoHow does it argue against structured programming? My argument is that "recognizability" is in the eye of the beholder. One programmer's "map is a powerful abstraction over transforms, for example loops" is another's "this is some cutesy code/math creole by a CS graduate who desperately wants to find nails to apply his functional programming and applied math hammer on". That's a fairly harsh way of saying that at some point the abstraction isn't clarifying, whether it's recognizable or not. Disclaimer: I'm a big fan of functional idioms (they're one of my favorite parts of Rust, for example). I'm not so much a big fan of absolutism or over-generalization.
- deleted 10y ago[deleted]
- skybrian 10y agoThe preference for maps and folds looks like a fad to me. I can use them but I don't think it makes the code any easier to understand, just different.
- Groxx 10y agoI dunno, ruby has some nice tendencies here, like `out = [1,2,3].map(&:to_s)` which is small and descriptive[1]. Compare that to: out = [] [1,2,3].each do |x| out.append(x.to_s) end IMO that's not fad material - that's progress. Maps and folds can totally be abused to produce inscrutable nonsense, but for small, common operations they're often much more obviously-correct. [1]: `&:method_name` is extremely-common shorthand for "call this method"
- XorNot 10y agoI had no idea what you were trying to do in the first paragraph whereas without knowing much ruby I can easily read the intent of the second.
- sheepmullet 10y agoThat has more to do with familiarity than anything else. A tale of two cities is an easier book for an English speaker than Les Aventures de Tintin. Map applies a function to each item in a collection. As pseudo-code: Collection.map(function) And in the parents example we have: [1,2,3].map(&:to_s) The only Ruby specific part is &:.
- Cthulhu_ 10y agoIt does though. Maps and folds - and functional programming in general - focuses on the /what/. For-loops on the other hand tell the compiler / cpu the /how/. Summing is a nice example. A naive for-loop will just iterate through the list, keep a variable around, add the next item in the list to it. In functional programming (or with a reduce), you tell it to sum in a more concise way - but more importantly, you don't tell the compiler how exactly it should do it. It's trivial with functional programming to make the task (for example) multithreaded or to use advanced underlying cpu tricks, without you as a developer needing to know how exactly it does what you ask it to.
- spion 10y agoThats not a strength of Go. Structural interfaces, channels and performant M:N green threads are its main strengths, and AFAIK there is no other language that provides a similar combination in a familiar C/ALGOL-like packaging. If such a language existed and had generics and Swift or Rust style error handling as well as some backing by a large-ish corporation / organization, I think that language would be preferred to Go. More expresiveness isn't always better. Examples that hit the sweet spot are C# / Swift (C# really needs algebraic data types). Beyond a certain point, you will start to lose users. Haskell is very expressive, but few will ever have the time or patience to learn enough to build their perfect monad transformer stack and take advantage of the mtl typeclasses to easily use it. Even though it does have M:N green threads, channels, STM and everything. In fact, Haskell could probably compensate for this and beat Go by having excellent library documentation and well written, focused tutorials for the working engineer.
- reikonomusha 10y agoI feel like maybe 10 years ago no one would utter something like "C# needs ADTs" because they didn't have mainstream appeal, despite computer scientists' understanding of them.
- spion 10y agoYes, things are moving forward, even if slowly :)
- tu7001 10y agoI don't know go, can't you write a map in it?
- mattnewton 10y agoNot a type safe one that works on your own types.
- s_ngularity 10y agoYou can't define a polymorphic function map, but you definitely could definitely define a map method for your own monomorphic container type.
- watwut 10y agoThe loop and map are equally readable, it is just that some people are used to one form more then the other. More importantly, how many character needs to be used for simple idiom like that has zero influence on how maintainable your system is going to be few months later on, how fast it is and so on. The difference between loop and map wont make you do less or more bugs. It may make you read the code few seconds longer first time you encounter form you are less used to - but then you will adjust and read it just fine.
- solidsnack9000 10y agoIt is not necessarily easy to recognize when a loop is a map or filter -- I think that's the issue. It's why someone like McSweeney would bring it up. The Python approach -- where maps and loops share a lot of syntax -- is maybe the middle way. On the one hand, it's not an approach that gives rise to `.map()`, `.collect()`, `.flat_map()` and so forth; on the other, it's marked out as something returning a result.
- lewisl9029 10y agoFunctions are trivially composable, while imperative loops are not. The difference that makes in terms of maintainability and readability of non-trivial applications is hard to overstate. Writing code in terms of small, composable, reusable functions with a clear single intent (through good naming), that you can then mix, match, and reuse to compose into larger functions is what makes good functional code so much easier to write, test, and reason about than imperative code. My favorite intro to functional programming concepts for those used to imperative coding is Sott Sauyet's Functional Programming presentation: http://scott.sauyet.com/Javascript/Talk/FunctionalProgramming/ http://scott.sauyet.com/Javascript/Talk/FunctionalProgrammin... The presentation makes heavy use of JavaScript and the RamdaJS library in its examples, but the concepts are universally applicable to any language with the necessary functional programming primitives. It also does a great job of comparing imperative and OO implementations of a solution to a problem vs the functional implementation. I highly recommend taking a look if you're even slightly interested in why so many people are starting join the functional programming bandwagon. So what I'm trying to say is, it's not just a matter of readability. Although if anyone still wants to argue that imperative looping is anywhere close in readability compared to functional composition for non-trivial cases (think multi-level nested loops vs composing multiple functions), then we should just agree to disagree since I don't foresee that becoming a productive discussion.