News for hackers. Stuff that matters.
Re:C++ Pattern Matching Proposal [pdf] by rb808 on Friday January 03, 2020 @09:02AM (#21945866)
Its seems all languages are just copying each other at this point. I know C++ hates to be left out of anything so maybe this is appropriate, but to me its really destroying the ecosystem.

It was great to have different languages having different paradigms but now you can do everything in everything and code bases I'm working on are a confusing mess.

Re:C++ Pattern Matching Proposal [pdf] by dgellow on Friday January 03, 2020 @09:14AM (#21945978)
But in this case, pattern matching seems way easier to follow and evaluate mentally than the verbose visitor approach already in the language, or something based on switches/if statements. That seems to be a good way to reduce the amount of confusing mess, at least for new developments.
Re:C++ Pattern Matching Proposal [pdf] by typon on Friday January 03, 2020 @09:12AM (#21945965)
This logic doesn't make sense. If something increases productivity and code quality, why wouldn't languages copy it? Ideally languages should also remove unnecessary features, which is actually the thing that makes C++ a confusing mess: it's prioritization of backwards compatibility over keeping complexity low.
Re:C++ Pattern Matching Proposal [pdf] by pjc50 on Friday January 03, 2020 @11:43AM (#21947541)
> languages should also remove unnecessary features

Languages are effectively immutable. Unless you can reach out and edit every single piece of code that breaks when you remove a feature, you can't remove a feature from a language. You can only create a new, almost identical language, and then spend a decade migrating people. This is what happened to Python2/3.

Very few things have been successfully deprecated in C or C++. Even massive security holes in the standard library.

Re:C++ Pattern Matching Proposal [pdf] by Supermancho on Friday January 03, 2020 @08:28PM (#21952111)
> You can only create a new, almost identical language,

Thats demonstrably false. Python was a loud transition, but most of the language warts and syntax is still there. Same as the Php and perl transitions and the wacky es6 or java. The list goes on.

Re:C++ Pattern Matching Proposal [pdf] by a1369209993 on Friday January 03, 2020 @09:32PM (#21952405)
> most of the language warts and syntax is still there.

> > new, almost identical language,

Emphasis added.

Re:C++ Pattern Matching Proposal [pdf] by Supermancho on Saturday January 04, 2020 @07:09PM (#21958621)
>> new, almost identical language,

Either it means it's a different language or it's a new language. The ambiguity in interpretation leads to a statement of non-meaningful change (tautology) or a statement of important change. The gracious interpretation is the only thing worth responding to, not quibbling over the possible non-statement.

Re:C++ Pattern Matching Proposal [pdf] by a1369209993 on Friday January 03, 2020 @09:30PM (#21952399)
> This is what happened to Python2/3.

Nitpick (and also proving your point): there is no language Python2; you mean Python vs Python3.

Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @10:22AM (#21946614)
> it's prioritization of backwards compatibility over keeping complexity low.

There are other languages on less-shaky foundations, but people don't use them for various legitimate and illegitimate reasons.

Re:C++ Pattern Matching Proposal [pdf] by nn3 on Friday January 03, 2020 @09:22AM (#21946051)
It's like human languages. They adopt useful words from each other all the time too. Why shouldn't programming languages do the same?
Re:C++ Pattern Matching Proposal [pdf] by smitty1e on Friday January 03, 2020 @09:45AM (#21946256)
Restated, nobody under the sun can write "The last, final language anyone could ever need."

Think of programming languages as a seminar where designers are crafting that Ur-language between themselves, and folks like me in the peanut gallery look on.

Re:C++ Pattern Matching Proposal [pdf] by de_watcher on Friday January 03, 2020 @09:13AM (#21945970)
C++ was always the language for constructing paradigms you choose with underlying mechanism you want.
Re:C++ Pattern Matching Proposal [pdf] by pjmlp on Friday January 03, 2020 @09:49AM (#21946293)
Just like PL/I, Object Pascal, Ada, Lisp,...

C++ wasn't the first multi-paradigm language, and it won't be the last.

Re:C++ Pattern Matching Proposal [pdf] by saagarjha on Friday January 03, 2020 @06:47PM (#21951579)
It’s probably the most popular one, though.
Re:C++ Pattern Matching Proposal [pdf] by de_watcher on Monday January 06, 2020 @02:20AM (#21967226)
I said multi-paradigm plus the ability to comfortably do the implementation to lowest level.

AFAIK Lisp is not that low-level, Object Pascal is okay but generics/codegen are 20 years too late for example, PL/I is a pile of every known feature at the time by design but it's hard to tell now.

Re:C++ Pattern Matching Proposal [pdf] by oefrha on Friday January 03, 2020 @11:18AM (#21947218)
What’s the downside of copying the good stuff? I think the examples aren’t confusing at all and are perfectly readable by anybody.

Honestly I’ll be deeply ashamed as a Python programmer writing cascading ifs when even C++ gets pattern matching. (Yeah, I know all the arguments against it.)

Re:C++ Pattern Matching Proposal [pdf] by Ragnarork on Friday January 03, 2020 @09:23AM (#21946060)
What is destroyed exactly by adding a feature to a language that could easily improve readability (which said language reaaaally needs), which you can also opt not to use if you don't like?
Re:C++ Pattern Matching Proposal [pdf] by jarfil on Friday January 03, 2020 @09:28AM (#21946117)
You can't opt not to use it if you have to work with someone else's code which does use it.
Re:C++ Pattern Matching Proposal [pdf] by Ragnarork on Friday January 03, 2020 @09:35AM (#21946172)
True, I should have been more precise.

What I meant is the language does not force this on you as The Right Way To Do Things™ and thus it mostly boils down to organizing with peers and agreeing on a consistent set of guidelines (which goes well beyond language features...)

Re:C++ Pattern Matching Proposal [pdf] by paulddraper on Friday January 03, 2020 @06:41PM (#21951526)
Yes, it affects the ecosystem.
Re:C++ Pattern Matching Proposal [pdf] by MaxBarraclough on Friday January 03, 2020 @05:04PM (#21950875)
There's a very good answer to that question: simplicity, minimalism, and stability.

C++ is a huge, complex language. It's probably its greatest downside. Making it even more complex, should only be done with very good reason.

If you doubt this, consider the continued popularity of C, a thoroughly anaemic language by today's standards, with no clear advantages over C++ except for its simplicity, minimalism, and that the language changes very slowly. Well, that and its existing adoption levels. It's not quite the case that every feature C has is also in C++, but it's very close, and I can only name one exception: variable-length arrays (an unpopular addition to C) are not officially supported in C++.

C++'s complexity means that:

* It's very difficult to learn. It's extremely difficult to learn well. It's just about impossible to learn in its entirety. This isn't an exaggeration. (Andrei Alexandrescu might be the closest we have to someone who knows all of C++. He's a world famous C++ expert. Mortals don't stand a chance.)

* Different C++ programmers know (and write in) different subsets of the language. Good C programmers know essentially all of C. (I'll admit I'm weak on C's bitfields, and I couldn't tell you every subtlety of its memory model, but when it comes to C++, there may be areas of the language I've never even heard of.)

* C++ style guides (such as Google's one, or LLVM's one) are long and complex documents, by necessity

* We will never have a fully complete C++ compiler that truly matches the language spec. This undermines the spec; the language you're really using depends on your C++ compiler. To put that another way: portability is harmed because different C++ compilers cannot be relied upon to support the same language features.

* C++ compilers are more prone to arcane bugs, than C compilers

* Different C++ compilers have different arcane bugs, harming portability

* It's far easier to develop tools for C than for C++ (compilers, IDEs, etc)

* There are more C compilers out there than C++ compilers, especially for targets like PIC, or for very obscure platforms, or for particular needs such as safety-critical work. There's even a formally verified C compiler ('CompCert') with near-complete support for C99's features. I doubt there will ever be a formally verified C++ compiler.

* C is easier to mechanically reason about; there are more static-analysis tools for C than for C++

* If C++ were simpler it might have given rise to stable ABIs, the way C has. Instead, even different versions of the same C++ compiler might not be interoperable.

* It's less predictable regarding performance. Template metaprogramming can bloat your binaries for seemingly no reason. In C however, all features of the language map naturally to assembly; the programmer can generally predict roughly what assembly will be generated. This matters to those working with operating systems, graphics, high-performance programming, or where side-channel attacks are a security concern.

C++ is also faster-moving than C, meaning:

* It takes more work to maintain your skills for reading other people's code

* Code can age. Old code looks different from new code, unless it's actively maintained, which means work and risks new bugs. If the language rarely changes, this problem goes away.

* If you're developing a compiler, you'd rather a stable language like C, so that you don't have to make a career out of keeping up with the latest additions to the language. Keeping up with the additions to C++ is more than any one compiler-engineer could hope to do.

There are very few 'conservative' languages like C (there are also Scheme and Forth), but it can be a language's greatest strength. Zig is hoping to be another such language, but we'll have to see if it succeeds.

With all of that said, I tend to favour C++ over C, and I really like pattern-matching. It's something that cannot really be 'faked' with templates or macros. (Another personal favourite feature of mine, named arguments, is similar in that regard.) I think it's rather silly that the major OOP languages have until recently completely ignored this brilliant language feature from the functional programming world, as if it adds nothing over switch/case. Even D, an extremely feature-rich language, still lacks pattern matching.

Re:C++ Pattern Matching Proposal [pdf] by paulddraper on Friday January 03, 2020 @06:34PM (#21951482)
> There are very few 'conservative' languages like C

Go is a simple language, no?

It's higher-level than C, but no historical baggage, so probable comes out to the same complexity to fully understand the language.

Re:C++ Pattern Matching Proposal [pdf] by MaxBarraclough on Friday January 03, 2020 @06:59PM (#21951658)
Interesting suggestion, unfortunately I don't know Go so I can't really respond.
Re:C++ Pattern Matching Proposal [pdf] by rdm70 on Friday January 03, 2020 @06:44PM (#21951557)
You absolutely can add pattern matching to a language with powerful macros. One example that comes to mind is the optima library for cl.
Re:C++ Pattern Matching Proposal [pdf] by MaxBarraclough on Friday January 03, 2020 @06:57PM (#21951648)
I was referring to C's macros.
Re:C++ Pattern Matching Proposal [pdf] by MaxBarraclough on Saturday January 04, 2020 @07:38AM (#21954585)
Oops, I meant C++'s macros. StackOverflow tells me there are subtle differences.
Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @10:17AM (#21946560)
> all languages are just copying each other at this point. I know C++ hates to be left out of anything so maybe this is appropriate, but to me its really destroying the ecosystem. It was great to have different languages having different paradigms but now you can do everything in everything

I don't think you can do everything in everything. Try working with lazy immutable data structures in Rust, for one.

Or look at Dart - now has "non-nullable types," monadic error handling (sort of), but of course the whole thing is on shaky foundations so what's it worth?

Re:C++ Pattern Matching Proposal [pdf] by derefr on Friday January 03, 2020 @11:07AM (#21947085)
> Try working with lazy immutable data structures in Rust.

I don’t think this is that hard; you “just” need to construct the data structures as elements of an object-graph data structure, and then retrieve your data through an explicit thunk of the object-graph itself.

In lazy languages the object-graph data structure is implicit, but that doesn’t mean that the Rust version of the call site code needs to be any more verbose. It’s just the definitions of the data structures themselves that would be more unwieldy. (And you could probably build some generic lazy container types and mostly work with those.)

Think: what Objective-C does with autorelease-pool objects.

Re:C++ Pattern Matching Proposal [pdf] by steveklabnik on Friday January 03, 2020 @11:30AM (#21947373)
Here’s what immutable data structures look like in Rust: https://docs.rs/im/14.1.0/im/
Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @03:29PM (#21949982)
None are lazy, however.
Re:C++ Pattern Matching Proposal [pdf] by ChrisSD on Friday January 03, 2020 @10:43AM (#21946815)
> Try working with lazy immutable data structures in Rust, for one.

Why is that an issue?

Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @10:58AM (#21946992)
Well, it doesn't have the runtime to support laziness properly.
Re:C++ Pattern Matching Proposal [pdf] by fctorial on Friday January 03, 2020 @11:47AM (#21947588)
Why would lazy data structures need a runtime? Some kind of GC is necessary for immutable data structures, but wouldn't iterators and generators be enough for implementing laziness?
Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @03:32PM (#21950014)
> wouldn't iterators and generators be enough for implementing laziness?

If you can implement lazy finger trees with iterators I'd love to see it :)

Re:C++ Pattern Matching Proposal [pdf] by ChrisSD on Friday January 03, 2020 @11:10AM (#21947119)
Sure, it doesn't have much of a runtime at all but Rust does give a firm foundation to build on. Using an `Option` or the `once_cell` library is pretty ergonomic. At worse you use a function call to get a reference to the value instead of using it directly.
Re:C++ Pattern Matching Proposal [pdf] by DougBTX on Friday January 03, 2020 @11:26AM (#21947309)
Agreed, Rust can certainly handle lazy evaluation. All the iterator types for example are lazy, hence the .collect() method which eagerly evaluates a lazy collection.

Hiding the fact that a lazy value needs to be mutated to initialise it is a little more work (since a nice API lets the user treat the value as if it doesn’t need to be mutated), but is certainly possible.

Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @03:31PM (#21950003)
> All the iterator types for example are lazy,

It's not proper laziness as defined in Okasaki's thesis/book. One needs more complex things like lazy finger trees.

Re:C++ Pattern Matching Proposal [pdf] by paulddraper on Friday January 03, 2020 @06:39PM (#21951519)
The iterator is lazy.

The language is not.

Re:C++ Pattern Matching Proposal [pdf] by specialist on Friday January 03, 2020 @02:19PM (#21949311)
We design our languages which then design us. Variant of Churchill's quote about rebuilding their parliament chambers exactly as before.

Maybe think of language design as a search thru an n-dimension problem space.

There's the perennial trilemma of functional (LISP), imperative (APL), and object oriented (Simula), where your new language lands somewhere within that triangular design space.

Then add extra dimensions for type systems. Nominal vs structural vs whatever.

Then add some more for ideas swiped from declarative (SQL, VRML, LINQ), stack-based (Forth), REPLs (Logo), constraints (Prolog), and whatever else people cook up.

Ya, the churn is nutty making. But it's also awesome at the same time.

Re:C++ Pattern Matching Proposal [pdf] by agumonkey on Friday January 03, 2020 @09:07AM (#21945922)
> each other

by each other you mean the ml world right ? :p

Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @10:19AM (#21946577)
Functional programming seems to be taking on the world (J inspiring NumPy, ML features being used everywhere).
Re:C++ Pattern Matching Proposal [pdf] by gdxhyrd on Friday January 03, 2020 @12:02PM (#21947757)
Functional languages are nowhere to be seen compared to the rest.

Some subset of features inspired in them are used in some languages, but that has nothing to do with functional programming taking over.

Re:C++ Pattern Matching Proposal [pdf] by agumonkey on Friday January 03, 2020 @01:23PM (#21948746)
Honestly even if we're far from FP as mainstream (which I don't even wish). I woudln't have bet a dollar that so much features from lisp/ml would have crossed over this fast (I mean destruct, lambda, rest args, immutable let by default, option chaining ..).
Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @03:38PM (#21950069)
> option chaining

Where'd that come from? I thought that was monadic-do from Haskell.

Re:C++ Pattern Matching Proposal [pdf] by agumonkey on Friday January 03, 2020 @04:03PM (#21950334)
well I include haskell is the ml family (I admit it's twisting the words)
Re:C++ Pattern Matching Proposal [pdf] by dnautics on Friday January 03, 2020 @05:34PM (#21951063)
With Hooks, React has gone full FP, so, basically, the war is lost. Try finding a bootcamp programmer that wasn't taught React.

Sure, you can still build object components, but it's informally frowned upon.

Re:C++ Pattern Matching Proposal [pdf] by gdxhyrd on Tuesday January 14, 2020 @04:27PM (#22049407)
How is React or hooks "full FP"?

I think we have wildy different definitions of FP.

Re:C++ Pattern Matching Proposal [pdf] by agumonkey on Friday January 03, 2020 @10:39AM (#21946766)
Yes, haskellers will soon be celebrities.
Re:C++ Pattern Matching Proposal [pdf] by zelly on Friday January 03, 2020 @08:36PM (#21952142)
They are trying to convince people to use C++ instead of Rust for new projects.

No one with old C++ code is going to switch to these future hipster standards, let alone even C++14.

I think this standard bloat is digging its own grave. It will have the opposite effect. People who want the new shiny stuff will use the new shiny thing (Rust). The old timers will stay on C++11 all the way to 2070 when a man or machine finally rewrites everything in $(new lang).

Re:C++ Pattern Matching Proposal [pdf] by ahartmetz on Saturday January 04, 2020 @07:36AM (#21954577)
That is not my experience from real codebases at all. Generally, developers start using new features as soon as they become available in the standard (or minimum supported) compiler for the codebase.
Re:C++ Pattern Matching Proposal [pdf] by emodendroket on Friday January 03, 2020 @03:30PM (#21949993)
I think it's great. No need to switch languages when you just need some feature here and there.
Re:C++ Pattern Matching Proposal [pdf] by jokoon on Friday January 03, 2020 @12:58PM (#21948451)
This is a codebase problem, not a language one.

If there's a good idea, why not use it?

Re:C++ Pattern Matching Proposal [pdf] by bluGill on Friday January 03, 2020 @09:27AM (#21946095)
Almost all languages are turning complete. The only questions is the syntax: convenience of writing it and how fast it runs on the machine (either/both compile time and run time)

When you have a syntax that you like for whatever reasons (including because you have a lot of legacy code written in it) it makes sense to extend the syntax where possible to make it more convenient if you can do so within the constraints of performance.