News for hackers. Stuff that matters.
Re:Intro To Pattern Matching – Covers C# 9 by melling on Wednesday February 19, 2020 @10:25AM (#22366244)
We’re all slowing moving to functional programming.

One day we wake up and decide we basically know Haskell, OCaml, etc and take off the training wheels?

Re:Intro To Pattern Matching – Covers C# 9 by mumblemumble on Wednesday February 19, 2020 @10:57AM (#22366597)
I don't think so. Pattern matching and the like are just window dressing. The two true distinguishing features of Haskell are that it's lazy, and the compiler enforces referential transparency. Neither of those is something you can get by simply adding features to an existing language.

And, if you aren't working within those strictures, you're still just not even in the same universe. No matter how many variables you make immutable, you'll still be able to log events by just executing a log statement, and you'll still be able to create a function that talks to a remote service, and call it from anywhere. So, you might use a few functional-inspired features when they're convenient, but the actual structure of your program is probably still imperative to the core.

Re:Intro To Pattern Matching – Covers C# 9 by sweeneyrod on Wednesday February 19, 2020 @12:57PM (#22368087)
By this standard OCaml and Lisp aren't functional either.
Re:Intro To Pattern Matching – Covers C# 9 by mumblemumble on Wednesday February 19, 2020 @01:13PM (#22368260)
I wasn't intending to imply that they aren't. The standard being proposed when I originally wrote my comment was just "Haskell"; I think the "ocaml, etc" was a later edit.
Re:Intro To Pattern Matching – Covers C# 9 by damnyou on Wednesday February 19, 2020 @11:56AM (#22367343)
It turns out that that "window dressing" is by far the most practically useful part of functional languages.
Re:Intro To Pattern Matching – Covers C# 9 by mumblemumble on Wednesday February 19, 2020 @12:05PM (#22367472)
I keep wondering what it would be like to work in a language that gave some compiler support for ensuring that functions remain mostly pure. Like, perhaps mutating variables that are visible outside the function or getting input from external sources are disallowed, but logging and writing debug output are still permitted.
Re:Intro To Pattern Matching – Covers C# 9 by cylon13 on Wednesday February 19, 2020 @01:15PM (#22368293)
Haskell is like that with System.IO.Unsafe and Debug.Trace.
Re:Intro To Pattern Matching – Covers C# 9 by cultus on Wednesday February 19, 2020 @11:25AM (#22366967)
Haskell still doesn't have real referential transparency. It's all a matter of degrees and no language is pure, even Agda or Coq. The concept of IO as a world state you pass around is deeply flawed, especially with multiple cores. You cannot be in control of the world, so you don't really have equational reasoning. At any rate, there can be unsafePerformIOs lurking anywhere.

I really think delimited-continuation based algebraic effects are the way to go.

Re:Intro To Pattern Matching – Covers C# 9 by goto11 on Wednesday February 19, 2020 @10:32AM (#22366318)
Well F# is based on OCaml, and it have been recognized for some time that C# is adopting more and more features from F#. As the article alludes to, this is not without controversy. Some feel that C# is becoming too bloated, and if you want to program in a functional style, you could just use F# in the first place. C# is much more widespread though, so this makes functional idioms more broadly available.

On the other hand, C# have also gotten deeper support for pass-by-reference and stack allocation which I consider more low level features. So I don't think the development is purely in functional direction.

Re:Intro To Pattern Matching – Covers C# 9 by thrower123 on Wednesday February 19, 2020 @10:47AM (#22366493)
Every C# release, F# starts looking less and less compelling. There's already a level of friction, since so much of the underlying framework is C#-centric and littered with exceptions and nulls, and if you want to expose F# code to be consumed by C#, you have to dumb things down. And the tooling for F# is considerably less advanced than you get with ReSharper or even out-of-the-box in Visual Studio.

It's a bit of a shame; I suppose that is one of the reasons that some people in the F# community are really pivoting over to WASM and Fable for using F# in the browser.

Re:Intro To Pattern Matching – Covers C# 9 by Dolores12 on Wednesday February 19, 2020 @11:15AM (#22366839)
I think you need less refactoring in F# in first place. Recently, i've tried fsbolero and was really impressed. No way I return back to C#.
Re:Intro To Pattern Matching – Covers C# 9 by SuddsMcDuff on Wednesday February 19, 2020 @11:48AM (#22367251)
C# can only go so far down the road towards F# without introducing currying and partial application. I can't see those ever being introduced into C#.
Re:Intro To Pattern Matching – Covers C# 9 by LandR on Wednesday February 19, 2020 @12:10PM (#22367533)
You can sorta get partial application using lambdas, or whatever they called in C#

Like a poor mans hacky partial application, one argument at a time.

     namespace Bored
     {
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using static System.Console;
        internal static class Program
        {
           private static void Main()
           {
              var addFive = Add.Partial(5);
              addFive(6).Print(); // Prints 11
              Enumerable.Range(0, 5).Select(addFive).ForEach(WriteLine); // Prints 5 to 9
           }
           private static Func<int, int, int> Add = (int x, int y) => x + y;
        }

        internal static class Extensions
        {
             public static Func<T2, TR> Partial<T1, T2, TR>(this Func<T1, T2, TR> func, T1 t1) => t2 => func(t1, t2);
             public static void Print<T>(this T t) => WriteLine(t);
             public static void ForEach<T>(this IEnumerable<T> xs, Action<T> f) => xs.ToList().ForEach(f);
         }
     }
Define your partial extension method for each arrity to Func. I think it maxes at 16?
Re:Intro To Pattern Matching – Covers C# 9 by fiveminds on Wednesday February 19, 2020 @10:36AM (#22366377)
me to you can solve the same problem in 100 ways and each way can have its own tips and ticks and pors and cons! C# will be complex like c++ not for new developers only for experts!
Re:Intro To Pattern Matching – Covers C# 9 by runevault on Wednesday February 19, 2020 @10:40AM (#22366421)
While I don't entirely disagree with you, "default" c# style won't screw you up the way default c++ will, while masterful c# will give you a non-trivial amount of the benefits if they continue to make intelligent improvements.

Will it ever be perfect? Of course not. But I feel like the direction they are taking is a reasonable one.

Re:Intro To Pattern Matching – Covers C# 9 by goto11 on Wednesday February 19, 2020 @10:41AM (#22366435)
This is the basic dilemma for any language. You can evolve and grow bigger, or you can stay simple and pure. I think history show languages have to evolve to stay relevant - "small and elegant" languages like Scheme and Smalltalk are not widely used. But since you can't really remove existing features, evolving leads to more complex languages.
Re:Intro To Pattern Matching – Covers C# 9 by alkonaut on Wednesday February 19, 2020 @12:34PM (#22367786)
I think the gravity is towards a middle ground that looks like imperative, but is quite functional compared to C, Java, C++ or early C#.

Sum types, powerful type inference and and immutable-as-default.

Kotlin, Rust, Typescript are all recent-ish languages an all fit into this category. Meanwhile F# approaches it from the other direction (start with OCaml and sprinkle on some imperative and OO).

Re:Intro To Pattern Matching – Covers C# 9 by fiveminds on Wednesday February 19, 2020 @10:31AM (#22366307)
yes did you see the uncle bob video about programming future? before 11 years. --> it happing today
Re:Intro To Pattern Matching – Covers C# 9 by jaked89 on Wednesday February 19, 2020 @10:47AM (#22366500)
The ability to change value by ref is crucial to most real-world apps. This is not surprising, as those apps are modeled to represent a real, dynamic world.

Functional languages tend to disregard this, and demand composition over mutation. While this works for some domains, it's a burdensome complication for others.

Imperative languages are here to stay.

Re:Intro To Pattern Matching – Covers C# 9 by willtim on Wednesday February 19, 2020 @12:49PM (#22367987)
All the more reason to explicitly model time and not conflate it with the system runtime. As an example, banks have always added entries to a ledger such that the time history of events is explicit and preserved. Functional programming models this very well. An imperative programmer would probably write the final balance on a post-it note in pencil so that it could be destructively updated. Some OOP programmers have actually tried to model banking like this, because their language encourages it.

Another example might be a text editor buffer. Immutable persistent data structures allow one to get many features for free such as versioning, undo, lockless autosave. Memory is cheap now, there's less of a need to throw away some my edits with destructive updates. Even filesystems and databases have realised this is good idea. Destructive updates are bad for valuable data.

Imperative programming is only better for writing low-level system code, which is full of state that ultimately no one in the real world cares about.

Re:Intro To Pattern Matching – Covers C# 9 by apalmer on Wednesday February 19, 2020 @02:35PM (#22369162)
Your points are not 'wrong' but I think you are being overly broad in the conclusion you are drawing.

Imperative programming is the dominant programming model that 99.99% of all real world code for the last 60 years has been programmed in. It very well may be due to be replaced, but certainly cant just be hand-waved away

Re:Intro To Pattern Matching – Covers C# 9 by willtim on Wednesday February 19, 2020 @02:53PM (#22369354)
50 years ago 99.9% of computer programs were written in completely imperative assembly language programs, such that even arithmetic involved statements and temporary mutable variables. Fortran was a more mathematical higher-level language with boolean and arithmetic expressions. Functional programming just continues this trend, resulting in more mathematical, higher-level declarative languages, which as far as I am concerned, makes them more suitable for modelling real world business problems.
Re:Intro To Pattern Matching – Covers C# 9 by fiveminds on Monday February 24, 2020 @08:47AM (#22403898)
Turing has destroy everything what Alonzo Church did ;-)
Re:Intro To Pattern Matching – Covers C# 9 by jaked89 on Wednesday February 19, 2020 @03:30PM (#22369721)
FP didn't invent immutable data, or mathematical functions. It just makes it easier to use them for some domains, while complicating others.

Imperative programs can have isolated, pure subsections of functionality which are based on composition and immutability, without having to deal with the "ideological" strictness of FP.

You're considering only a minute aspect of large systems. Any real banking system has much more than a ledger to deal with. And most of it involves huge amounts of state, which you can't just pile on top of RAM, or waste CPU on. Anything that doesn't serve a real business/user purpose is just waste.

And text editors don't need FP to support undo either. I'm not sure what point are you trying to make.

The most successful editors in the market, supporting all the features you mentioned, do quite fine with imperative, and in fact, I'm not aware of any meaningful editor written in a FL.

> Memory is cheap now

Not really. This comment strikes me as if it comes from someone who never dealt with significant amount of data.

FP can be extremely wasteful; take head-tail lists for example, which are the default container in many FPs. They waste object-container data, pointer data, and scatter the list items, causing cpu cache misses.

Claiming that imperative is only better for low-level is extremely disconnected from reality. Try writing a game with FP, and I assure you no one will care for code "beauty" when FPS sucks.

Sometimes, arguing with FP purists feels like debating socialists.

Also: go ahead and downvote me, as apparently FP zealots can't tolerate questioning their religion.

Re:Intro To Pattern Matching – Covers C# 9 by willtim on Wednesday February 19, 2020 @04:28PM (#22370287)
> Imperative programs can have isolated, pure subsections of functionality which are based on composition and immutability.

And functional programming languages can support imperative programming and mutation, even Haskell. It's a question of what should be the default, which depends on the domain you are working in.

> Any real banking system has much more than a ledger to deal with.

Most banking systems are cobbled together from third-party components and libraries. Low-level languages aren't really needed. Many banks use Python, which is orders of magnitude slower than Haskell.

> This comment strikes me as if it comes from someone who never dealt with significant amount of data.

Actually I have a background in distributed computing, where functional programming abstractions have made processing large amounts of data much easier (MapReduce, Spark).

> FP can be extremely wasteful; take head-tail lists for example, which are the default container in many FPs.

This is a strawman. I can write inefficient code in any language. C++ code can be littered with pointer indirection and memory barriers.

> Sometimes, arguing with FP purists feels like debating socialists.

I am a socialist.

Re:Intro To Pattern Matching – Covers C# 9 by moomin on Wednesday February 19, 2020 @10:51AM (#22366535)
This is rather heavily debunked already. You might want to investigate that.
Re:Intro To Pattern Matching – Covers C# 9 by jaked89 on Wednesday February 19, 2020 @11:41AM (#22367166)
You'd be more convincing providing a substantial response instead of referring me to "investigate". I've used FP extensively, and they all make mutation very hard, by design.

Do you disagree with this premise? Do you disagree with my claim that the world is dynamic, and that FPs are limited in representing them?

Please address my points specifically if you have anything meaningful to contribute.

Re:Intro To Pattern Matching – Covers C# 9 by moomin on Wednesday February 19, 2020 @12:40PM (#22367870)
I would be more convincing, but the whole point of my comment was that you need to do the work to get up to date with where the debate is. Don't ask other people to do the work for you.

Anyway, FYI that's why you've been multiply downvoted. Not because there's some FP cabal who downvote pro-imperative comments.

Re:Intro To Pattern Matching – Covers C# 9 by jaked89 on Wednesday February 19, 2020 @12:53PM (#22368031)
Didn't expect otherwise. You'd use a logical response if you had one.

My comment is a direct response to the OP who implied FPs are going to "take over".

I'm being downvoted probably by FP zealots who can't deal with the idea that their solutions aren't perfect or universal.

BTW, I'm not "against" FP in general at all. I have used it in the past, and it has useful idioms to contribute to imperative languages, and it's perhaps useful on its own in some domains; I'm just pointing out its limitations.