86 points · by lucasmreis · 9y ago · 65 comments
I know a lot of people don't want to hear this but these types of languages, functional first, are the future of our industry. (In the sense that in the 2000s Java like laguanges were the future of our industry). I might be reaching here, but in my opinion, these are the right languages for the Cloud and that's why they are getting so popular.
I do not think we're going in this direction, necessarily.
In the meantime, you probably need slightly, but not massively, better developers.
Lots of stuff that is easier to do. Not much that is harder.
We'll hear about these more and more for sure.
Companies like Facebook aren't what the majority of us works on.
So when selling languages to management "look Facebook does it" usually doesn't help at all, what one needs are how that adoption will help those IT costs go down.
I can see a lot of value for that in non-tech companies that correctness is crucial, like finance, insurance, health...
Always goes that way.
However, for complex representational systems, including both transactional and continuous systems in business, commerce and industry, other languages and paradigms can remain better suited.
Hello. Respectfully, what is a complex representational system? Why are other languages/paradigms better suited over a language like F#?
A database is one example.
A database is also global mutable state for the programs that write to it, and that significantly compromises the advantages of using functional programming languages for such programs. You might start with some nice pure functional code, but the database adds massive side effects.
1. Representational systems
a. Transactional systems [1], based around actions that need to be recorded, typically for commercial or legal reasons, like software used to record your purchases, payments, reservations, participation, interactions, obligations, results, commitments, plans, and significant events.
b. Non-transactional continuous systems, like software controlling an elevator, warehouse conveyor system, or a vehicle engine management system.
Mainstream languages will incorporate functional features and remain popular, and they will not be superseded by pure functional languages. Java and C# are already doing this.
* mutable by default
* OO by default
* null by default
* structural equality a pain to implement
* immutable types a pain to implement
* verbose syntax / failing at the DRY principle
* statement based rather than expression based
* large codebase following those idioms
I don't think they'll not remain popular, but I think a more important share of people will eventually "get it" that there are alternative approaches which are sound, same or greater potential to achieve and thriving eco-system.
If you want to sell a language to the upper layers, you need a list of business reasons, not language features.
There are ways a C# aficionado would take to try to not be so verbose, but those solutions won't be considered idiomatic by 99% of C# developers.
At the end of the day, codebase size matters a lot.
I'm currently learning a couple of LISP variants (Closure and LFE). With ClojureScript, Elm, PureScript, BuckleScript, and even plain ole ES6, functional on the frontend is more compelling than ever.
Otherwise, great article. This is exactly how I learned to program with Scheme: mosel the domain carefully, slowly building up helper functions, and conposing at the end.
And, as some commenter on Disqus said, probably the right thing to do would be returning an Qty option from the function, and treating it properly.
I have no experience with Scheme, but already worked with Clojure - it was actually my "gateway" to functional programming languages, hehe!
Then using a bit of F# Quotations, I can convert most match queries to XPath queries and query SQL Server directly (still work-in-progress).
But running into performance problems, so it's not 100% done.
http://stackoverflow.com/questions/41949177/f-data-types-sql...
(defstruct product nil
sku
price)
(defstruct event nil)
(defstruct add-to-basket event
product
quantity)
(defstruct line nil
product-sku
quantity
line-total)
(defstruct basket nil
lines
total
(:postinit (me)
(set me.total [reduce-left + me.lines 0 (usl line-total)])))
(defvarl empty-basket (new basket))
(defun build-line (product quantity)
(new line
product-sku product.sku
quantity quantity
line-total (* quantity product.price)))
(defmeth basket add-to (me product quantity)
(flet ((transform-line (line)
(if (equal line.product-sku product.sku)
(build-line product (+ line.quantity quantity))
line)))
(let* ((transformed-lines [mapcar transform-line me.lines])
(product-already-in-basket (nequal transformed-lines me.lines)))
(if product-already-in-basket
(new basket lines transformed-lines)
(new basket lines (cons (build-line product quantity) me.lines))))))
(defmeth basket update (me event)
event.(add-to me))
(defmeth add-to-basket add-to (me basket)
basket.(add-to me.product me.quantity))
REPL: $ txr -i typemodel.tl
1> (new add-to-basket product (new product sku 42 price 5) quantity 4)
#S(add-to-basket product #S(product sku 42 price 5) quantity 4)
2> (new basket)
#S(basket lines nil total 0)
3> *1.(add-to *2)
#S(basket lines (#S(line product-sku 42 quantity 4 line-total 20)) total 20)
(The silly implementation of the product-already-in-basket is a literal transliteration of the original.)If you see me designing programs like this in real life, just whack me on the head, please!
(defmeth basket add-to (me product quantity)
(labels ((insert (lines)
(tree-case lines
((line . rest) (if (equal line.product-sku product.sku)
(cons (build-line product
(+ line.quantity quantity))
rest)
(cons line (insert rest))))
(() (list (build-line product quantity))))))
(new basket lines (insert me.lines))))