13 ms·
An excellent list. Regarding functional programming, I recommend starting with a gentle approach that doesn't require picking up a new language: 1. Stop creati
by braindongle 6y ago
An excellent list. Regarding functional programming, I recommend starting with a gentle approach that doesn't require picking up a new language:
1. Stop creating counters/loops and become facile with map, reduce, and the like. This will shift your thinking away from blocks and toward functions.
2. Take the time to really understand what side effects are, and start avoiding them everywhere they are not necessary. Keep scopes as local as is practical.
3. When you start toying with functional programming per se, make sure you really have your head around recursion. That's where much of the magic concision comes from.
- 0xEFF 6y agoA gentle way to get into the "functional" mindset is to write small a script and then use it to process some collection with xargs. xargs is analogous to map() in this situation, and the script needs to have limited side effects to work well with concurrency. xargs -P4 for example.
- vmchale 6y ago> I recommend starting with a gentle approach that doesn't require picking up a new language: But then you don't get any of the newer stuff.
- biomodel 6y agoFunctional programming has been a game changer for me as well and has enabled me to write larger and more complex programs that are easy to maintain and reason around. I highly recommend cytoolz for python
- amelius 6y ago> An excellent list. Regarding functional programming, I recommend starting with a gentle approach that doesn't require picking up a new language: But at least make sure that your language supports closures.
- MaxBarraclough 6y ago> I recommend starting with a gentle approach that doesn't require picking up a new language Disagree. This is likely to 'dilute' the lessons of functional programming, as it were. If you learn to program in idiomatic Clojure/OCaml/Haskell/Scheme, you can be relatively sure you really have picked up the principles of functional programming. If you merely attempt to apply new principles in an environment you're already comfortable in, things aren't going to 'click' in the same way. Beside that, plenty of languages simply lack the facilities needed to effectively use the concepts of FP, as vmchale says.
- jimmaswell 6y agoSome people say learning Latin makes you a better writer, smarter, etc. even if you're unlikely to directly use it. Dubious claims but it feels like FP can be like that.
- MaxBarraclough 6y agoSure. When learning Latin, well, you learn to read and write Latin. You absorb the language's principles by learning the language, not by trying to highlight them in a language you already know. That can only give a much shallower appreciation.
- 9wzYQbTYsAIc 6y agoNot quite true - many complexities of grammar are shared between the languages and it is often useful to structure the learning of Latin around the English patterns of grammar.
- kls 6y agoThe thing about learning Latin (not that I am great at it), at least for an English native speaker, and the epiphany English language speakers have, is the realization that language can have structure and can be discover-able, if I know a root word then I can almost be sure that I know the meaning of con, re, dom etc. There is just no equivalent to that in English other than the Latin origin words we borrowed, because we just assimilate any words we like and make up new ones as we see fit. An example would be beaucoup a Vietnamese word but most US English speakers would know it means big. Without the historical reference of a movie you would not have a reason or rhyme why an Asian origin word made it into English. There is literally no reason or rhyme to most of the spoken language and I think that is the epiphany, that some people actually thought out a logical way to create a language and via that logic it is discover-able.
- xupybd 6y agoIsn't beaucoup French?
- chrischen 6y agoAgreed on gentle approach. I've started using libraries like Ramda for JS, which is especially designed to ease people into functional patterns. I then moved to FP-TS, which makes more heavy use of haskell-like patterns and monads. The hard part isn't the syntax of whatever language, but understanding the new patterns and way of thinking, which you can do with a simulation layer like FP-TS (for typescript/javascript). The functional patterns and emphasis on types makes your code robust and more correct. It emphasizes correctness, which is ultimately what your job is as a programmer. Optimization comes after.
- vorticalbox 6y agoI too have started down the fp router with ramda and ramda-adjunct. Though other people at my work dislike it due to them not understanding what's going on
- Fellshard 6y agoHad the same result, and had to settle for the middle ground of (lodash | underscore; I don't recall which now.) There's a lot of resistance to adopting anything with the name functional, and that resistance is often seen in a /refusal/ to try to understand instead of a mere lack of understanding: people put up walls straightaway. I expect many need motivating examples to guide them to it. Languages like Kotlin are pointing the way towards that middle ground far more effectively than, say, Scala did.
- pk_kinetic 6y agoThere could be other reasons for disliking it other than not understanding what’s going on. Maybe other people are working on tight deadlines and don’t have the time or mental energy trying to understand an entirely unfamiliar programming paradigm. I would want to program in functional too, but I would seek out projects or teams that already use functional. I’d never introduce a functional language to an already established team or project, unless of course, I was the CTO and there were clear benefits.
- 6y ago
- torb-xyz 6y agoThis! What is funny that is that I started doing this before I knew anything at all about functional programming, I just started to avoid stuff that I had painful experiences with. Later I read a couple of chapter of SICP and then I really changed and my programming hasn't been the same since. The language I use at work is JavaScript and while SICP isn't for JavaScript, nothing else has changed my JavaScript for the better to that degree.
- bmn__ 6y ago> while SICP isn't for JavaScript There's a port. https://sicp.comp.nus.edu.sg/ https://sicp.comp.nus.edu.sg/
- kyawzazaw 6y ago> 1. Stop creating counters/loops and become facile with map, reduce, and the like. This will shift your thinking away from blocks and toward functions. I am not very comfortable with this. How can I learn to do this in traditionally non-FP languages like Java? (Am CS undergrad student)
- Jtsummers 6y agoCaveat: I haven't touched Java in years, and that was not even a current version of Java at the time (well, it was old code made to run on the then-current JVM, but not utilizing any features introduced after 2006 or so). I'm assuming these are good resources, but I'm not sure. https://developer.ibm.com/technologies/java/series/java-8-idioms/ https://developer.ibm.com/technologies/java/series/java-8-id... List of articles relating to idiomatic Java 8 code. Some of these touch on using lambdas and functional idioms. https://developer.ibm.com/articles/j-java8idioms3/ https://developer.ibm.com/articles/j-java8idioms3/ This one shows a few of the functional-styled methods that can be used (foreach, takewhile, iterate, etc.). https://developer.ibm.com/articles/j-java8idioms2/ https://developer.ibm.com/articles/j-java8idioms2/ Shows the collection pipeline pattern. I have experience with the same things in C# and other languages, the way they're using them in these articles are what I'd expect from a comparable API.
- braindongle 6y agoI can't speak authoritatively about Java, but it looks like map-reduce is available in Java 8 by casting a collection to a stream [0]. Considering the definitions of map and reduce can help one see how they can replace loops/counters: MAP: Take a collection, say a list/array or a dictionary/hash, and perform some function on each member of the collection, returning a new collection who's members are the return values for each original member. It's a loop, but no loop! REDUCE: Do the same thing as map, but carry along an output variable, and have your function's output for each member (potentially) mutate that output variable. Summing is a basic example. I'm not specifically recommending preferring this in Java as a step towards functional programming. It's in, uh, more terse languages like Python and Ruby where the payoff is obvious [1][2]. And among not-functional programming languages, it's not just dynamic languages, either. Consider Dart (and seriously, consider Dart) [3]. Also, Javascript, which has had many features shoehorned-in over the years, has these and related functions. [0] https://www.java67.com/2016/09/map-reduce-example-java8.html https://www.java67.com/2016/09/map-reduce-example-java8.html [1] Double some numbers Python: result = map(lambda x: x + x, array_of_numbers) [2] In Ruby: result = array_of_numbers.map{|x| x + x} [3] In Dart: result = arrayOfNumbers.map((x) => x + x).toList();