News for hackers. Stuff that matters.
Re:Near Future of Programming Languages [pdf] by Chris_Newton on Monday October 30, 2017 @12:02PM (#15586037)
I guess you're referring to languages that are not-quite-without-side-effects, but I'd say the biggest influence the functional paradigm has had on other (imperative) programming languages is actually the addition of higher-level data manipulation operations.

I tend to agree. The two big wins from a more “functional” style, from my perspective, are the clear emphasis on the data and the way effects are more explicit and controlled.

I want things like higher order functions and algebraic data types and powerful interface/class systems. With those I gain many useful ways to represent and manipulate data that I don’t have in most languages today.

In a world where most mainstream languages are just discovering filter, map and reduce on their built-in list types, a language like Haskell gives me, out of the box, tools like mapAccumWithKey that work with any data structure as long as it provides the specific, clearly defined interfaces required for the algorithm to make sense.

In a world where most mainstream languages are worrying about accidentally derefencing nulls or whether there’s a proper type for enumerating a set of values, functional languages routinely use algebraic data types and pattern matching, and some go much further.

Arguably, these aren’t really functional concepts at all, in that you could have them just as well in an imperative language. However, in practice it is the functional-style languages that are far ahead in these areas, because they are a natural way to work in languages that emphasize composition of functions and careful, explicit handling of data.

I also want to know that I’m not applying effects on resources unintentionally, or sharing resources without proper synchronisation, or trying to apply effects on resources in an invalid order, or failing to acquire or release resources properly, or leaving resources in a mess if something aborts partway through an intended sequence of effects. This aspect goes a lot further than just making data constant-by-default, but it certainly doesn’t require trying to remove state and effects altogether. These things aren’t so much about making my code more expressive but about stopping me from making mistakes.

I want a language that will stop me from accidentally modifying a matrix in-place in one algorithm while some other algorithm has a reference to that matrix that it assumes won’t change. I don’t want a language that will stop me from ever modifying a matrix in-place. Sometimes modifying things in-place is useful.

I want a language that will be explicit about the initialisation and lifetime and clean-up of a locally defined cache or temporary buffer. I don’t want a language that tells me I can’t cache a common, expensively computed result 15 levels deep in my call hierarchy without changing the signature of every function on every possible path to that point in the code, or a language that will let me do whatever I want but only if I use some magic “unsafe” keyword that forfeits most or all useful guarantees about everything else in the universe as well.

In this respect, my personal ideal programming style for most tasks very much would be a hybrid of imperative/stateful and functional/pure styles, with the key point being that the connections between them should be explicit, obvious and deliberate.

Re:Near Future of Programming Languages [pdf] by smaddox on Monday October 30, 2017 @03:58PM (#15588369)
Rust doesn't require use of unsafe for cacheing 15 levels deep if you use the right primitives, i.e. a Mutex. If you dont use safe primitives, then yes you need to use the unsafe keyword to mark the code as unsafe. How is that unreasonable?
Re:Near Future of Programming Languages [pdf] by Chris_Newton on Monday October 30, 2017 @04:29PM (#15588602)
I was commenting on the beneficial influences from functional programming on mainstream languages, and noting that a purely functional programming style with no effects isn’t (IMHO) particularly necessary or desirable.

I don’t know much about Rust so I can’t comment much on that. The intended point of my example was that in a purely functional environment, you can’t have a local, low-level cache, because updating a cache is inherently stateful. So either you need something like a mechanism that lets you break the rules locally, like say unsafePerformIO in Haskell, or you need to infect your entire call chain with whatever mechanism you use to manage effects top-down. While that is perfectly reasonable, given the constraints you choose by adopting a purely functional language, I don’t think it’s particularly helpful.

My conclusion was that I’d rather have a hybrid of imperative and functional styles, contrary to the suggestion in the original presentation and in general agreement with stdbrouw’s comment.

Re:Near Future of Programming Languages [pdf] by SiVal on Monday October 30, 2017 @08:58PM (#15590361)
Are there any languages you know of that are somewhat close to what you describe?
Re:Near Future of Programming Languages [pdf] by pdimitar on Friday November 03, 2017 @05:10PM (#15622230)
Unless I am misreading your question... Erlang / Elixir?

They are purely functional in the sense that NO VARIABLE inside your code can be ever mutable.

However, they do have ETS (which is an in-process cache inside the VM) which is fully mutable and people have long made wrapping libraries around it for transparently working with mutable arrays, double-linked lists, queues, matrices, graphs and what have you.

The philosophy basically is "always work with immutable data except when mutable is more performant or is otherwise more practical". They don't shut the door on you, they just force you to make your intention to work with mutable storage very explicit and clear. That helps a lot when you go hunting inside your code for side effects, too.

As a maturing Elixir dev I can say this philosophy works incredibly well in practice. Code is smaller, much more readable, you don't worry about side effects like ever -- except in very, and I mean VERY RARE occasions (for 1 year of working with it I only had to do that twice) -- and finding a bug is times faster compared to Ruby, Javascript, PHP, Java.

Re:Near Future of Programming Languages [pdf] by Chris_Newton on Tuesday October 31, 2017 @12:51AM (#15591151)
None of the programming languages that I know well myself provides the sort of balance I’d like to see between:

(a) strong visibility of and control over effects,

(b) an emphasis on powerful tools to represent and manipulate data, and

(c) straightforward imperative/stateful aspects when required.

Of course that isn’t to say that no such language exists, but if it does then sadly I have yet to become aware of it. New ideas are always welcome…

Re:Near Future of Programming Languages [pdf] by andreaferretti on Tuesday October 31, 2017 @03:07AM (#15591536)
You may want to try Nim. It is an imperative language with meta programming capabilities, some functional features and an effect system
Re:Near Future of Programming Languages [pdf] by flavio81 on Tuesday October 31, 2017 @12:36AM (#15591106)
Yes, they exist and have been used for decades; two well known examples are Common Lisp and Scheme.

For example you can do functional, imperative and OO programming in Common Lisp, and it brings extensive features for working in all these three paradigms.

More recent examples, Racket and Julia.

Re:Near Future of Programming Languages [pdf] by Chris_Newton on Tuesday October 31, 2017 @01:32AM (#15591287)
There are several reasonably well-known languages that bridge the functional and imperative worlds in one way or another. However, I’m looking for more than just that. In particular, I’d like to have good tools for both imperative/stateful and functional/data-transforming coding, but all within a safe, structured environment in terms of effects/external interactions/observable behaviour.

Now, I am by no means a Lisp expert, so it’s entirely possible that I’m completely unaware of something here. However, I’ve yet to encounter much of an effect system in any flavour of Lisp. Indeed, it’s hard to see how the sort of explicit visibility and control of effects that I’d find useful could be achieved in a language with primarily dynamic typing using any of the approaches I’ve encountered so far.