News for hackers. Stuff that matters.
Re:What If C++ Abandoned Backward Compatibility? by badsectoracula on Saturday March 28, 2020 @05:18AM (#22710093)
It'll most likely be abandoned in droves. One of the main reasons to stick with C++ (and C) is that the investment you put in the code you're writing right now, no matter how fugly it is, will be there and keep working in the future.

Also:

> I think it also makes sense for C++ developers whose projects are relatively short-lived, e.g. some games.

There is a difference between games and engines - the games might be short lived, but most C++ engines are very long lived, going back decades (e.g. see how the recent Half-Life Alyx can trace its codebase back to Quake 1 or pretty much anything based on the Unreal Engine going back to the mid-90s - there are screenshots of UE1 running on what appears to be either Windows 3.1 or NT 3.51). Even when "engines" are being made "from scratch" this is often a marketing gimmick and the "from scratch" was just renaming the engine because it got a new rendering model and people can't tell the difference. EVEN when this isn't case, often new engines are based on existing code and/or libraries.

Re:What If C++ Abandoned Backward Compatibility? by kllrnohj on Saturday March 28, 2020 @03:57PM (#22713873)
> but most C++ engines are very long lived, going back decades

While true the engines are also staffed and can absolutely keep up with changes. They regularly are tasked with new toolchains, platforms, OSes, and APIs to leverage already. This would just be more of the same, and if you look at the goals of the paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p213...

That lines up pretty damn well to what game engines want as well.

> One of the main reasons to stick with C++ (and C) is that the investment you put in the code you're writing right now, no matter how fugly it is, will be there and keep working in the future.

I think you should read the actual paper instead. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p213...

The things they talk about actually abandoning are things like byte sizes other than 8-bits or source code in file systems that don’t support file extensions or nested directories.

Chances are any existing C++ codebase is already not compatible with such systems that they want to more formally deprecate/abandon in the first place.

Re:What If C++ Abandoned Backward Compatibility? by theamk on Monday March 30, 2020 @12:37AM (#22725289)
You are talking about section 1.8. I agree, it is not that scary. What is scary, however, are sections 2.1 and 2.2. They contain stuff like this:

> Our experience is that providing broad ABI-level stability for high-level constructs is a significant and permanent burden on their design. It becomes an impediment to evolution, which is one of our stated goals.

This does not name it, but doesn't this refers to all those discussions about changing internal representation of std::string, std::vector and so on?

This does sound pretty scary. Once you have separate classes for "C++23 std::string" and "older std::string", you can no longer link together files built with different versions.. and this means you lose a lot past compatibility.

Re:What If C++ Abandoned Backward Compatibility? by kllrnohj on Monday March 30, 2020 @01:47PM (#22730293)
> you can no longer link together files built with different versions

True but this is already something that isn't really "supported" broadly. Some standard libraries work hard to keep that working, but others tend not to, and nobody knows if it's supposed to work reliably or not. And support for this binary compatibility also varies across platforms, like I don't think Microsoft bothers since you're supposed to always bundle a specific version of the runtime with your binary.

Single-version prebuilt libraries become more of a problem, but are those that widespread vs. source-based libraries?

But I think the broader point here that the paper is really pushing is for the committee to actually make a statement on things like this instead of their historically vague "it sort of works but we're not saying it will or indeed saying anything at all"

Re:What If C++ Abandoned Backward Compatibility? by bruxis on Saturday March 28, 2020 @05:24AM (#22710108)
Agreed, I think looking at the Python 2 and 3 migration catastrophe gives a glimpse into what this could look like, but I imagine it would be much worse given the types of (large) projects that are backed by substantially "dated" C/C++ code.
Re:What If C++ Abandoned Backward Compatibility? by phire on Saturday March 28, 2020 @06:09AM (#22710258)
You could do so much better than the python 2 to 3 transition.

If the python 3 interpreter could still run python 2 code. If you could mix and match python 2 and 3 code on a per-module, per-file or even per file basis, then the transition could have been so much smoother.

Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Saturday March 28, 2020 @06:15AM (#22710274)
The reasons the transitions worked were that:

- the languages were not that different, so no need to learn the new version

- python core devs gave 10 years to make the transition. Then extended it.

- it was possible to write code running on python 2 and 3

- python is very expressive, hence the code base have way less numbers of lines than in C++

- python cared only about one implementation, Cpython. The rest of the world needed to follow. Some didn't, like Jython and stackless, and the community didn't blink.

Despite all that, the transition was very painful.

Re:What If C++ Abandoned Backward Compatibility? by ComputerGuru on Saturday March 28, 2020 @08:11AM (#22710643)
“Worked?” Nothing about the Python 2 to 3 transition “worked” and people are still aghast that’s Python 2 is being EOL’d.
Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Saturday March 28, 2020 @12:04PM (#22711939)
I've been coding in Python for 15 years, and from what I see in the numerous places I get to work, yes, it worked.

It's just that aghast people are the most vocal. You don't hear the 90% of people that are happy. They don't take the time to speak up. But the unhappy complain all the time.

Re:What If C++ Abandoned Backward Compatibility? by ComputerGuru on Sunday March 29, 2020 @12:37AM (#22716459)
I’m not speaking about developers complaining, I’m speaking about the fact that it’s still a fractured ecosystem and plenty of popular programs, packages, and scripts still in use or even still actively developed rely on or integrate with Python 2 (exclusively).
Re:What If C++ Abandoned Backward Compatibility? by joshuamorton on Sunday March 29, 2020 @05:44PM (#22723039)
> I’m not speaking about developers complaining, I’m speaking about the fact that it’s still a fractured ecosystem and plenty of popular programs, packages, and scripts still in use or even still actively developed rely on or integrate with Python 2 (exclusively).

Such as? What actively developed tools or ecosystems rely or integrate with python2 exclusively?

Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Sunday March 29, 2020 @03:30AM (#22717086)
There are people still using Windows XP.

There are programs still using COBOL.

That's life in IT.

Re:What If C++ Abandoned Backward Compatibility? by rpedela on Saturday March 28, 2020 @07:19PM (#22715055)
Yeah I'm one of the happy ones. I always loathed Python 2 and text handling, Python 3 was a huge improvement from my perspective.
Re:What If C++ Abandoned Backward Compatibility? by slovenlyrobot on Saturday March 28, 2020 @08:35AM (#22710756)
I'm several years into the "upgrade" and find myself still swearing daily at the idiocy of the whole thing. Hundreds of scripts used maybe once a year, such as 'dups.py' I tried to run today, broken by a missing parenthesis, and a function moved around.

Utterly pointless and reputationally ruinous. I don't do serious work in Python any more

Re:What If C++ Abandoned Backward Compatibility? by joshuamorton on Saturday March 28, 2020 @07:33PM (#22715135)
That has...nothing to do with python3 though, that's just your broken code being broken.
Re:What If C++ Abandoned Backward Compatibility? by slovenlyrobot on Monday March 30, 2020 @04:59PM (#22732234)
I recognize it may be difficult to understand, but this is a thread about backwards compatibility. Of course if I had any faith in the contemporary Python community, I would still be treating Python as a serious programming language and not be suggesting this is a difficult concept for someone to grasp.
Re:What If C++ Abandoned Backward Compatibility? by joshuamorton on Monday March 30, 2020 @05:25PM (#22732432)
I'm not sure what you're getting at. Perhaps if you could translate to less-smug, the rest of us could understand.
Re:What If C++ Abandoned Backward Compatibility? by slovenlyrobot on Monday March 30, 2020 @07:10PM (#22733115)
There's really not much to it, but if it's a foreign concept it may require a kind of conceptual leap. Essentially, this code worked perfectly well, and suddenly it no longer worked. From your perspective, as you quite effortlessly put it, this code is broken. For others elsewhere in more conservative parts of the world, it was not my code that broke, but the surrounding ecosystem.

There is a fabulously unending depth to explore in the chasm lying between these opposing world views. It would be more than possible to write a book on the topic and fail to cover it all, however here are some of the most important aspects, from my perspective at least:

* given a perfectly functional tool relied on heavily by its user to perform their job, and given that tool suddenly decides to change shape such that it no longer fits the user's hand without retraining, nor fits with the remainder of the user's toolset, including custom tools the user has invested in producing, the continued utility of the no-longer-functioning tool is called into question, along with a deserved reappraisal of the tool's applicability in the context of the user's original intended problem domain.

* when the reason for its reshaping is to solve what are highly important problems from the perspective of the tool, but much less so from the perspective of the average user, and that user's application of the tool to real world problems, it can no longer be said that the tool is simply an implement that may be called and relied upon at any point in future -- the tool develops a chaotic life and importance all of its own, and may choose to reshape once again at any future moment (and indeed in this case it has). It is no longer a tool, but some sentient entity demanding unpredictable ongoing costs and attention paid all of its own.

* given a tool that promises to cease functioning 'correctly' at any future moment based on its own whim, preferences, industry fashions and styles, in an ecosystem where many similar such tools exist that explicitly promise not to cease functioning over the same time period, it is a fool's errand to pick the tool that promises to externalize additional costs on the user when alternatives exist that avoid any such cost.

* given tool designers who externalize almost frivolously minor technical costs on to every user, where each 'minor' change is amplified perhaps 10000 times over and directly translates into expensive engineering time, the question is easily raised whether the philosophy of the tool is appropriate for its advertised utility, and whether continued reliance on the tool makes business sense. In economic terms, what was the cost to productivity of the retraining and re-tooling of users compared to any alleged future productivity improvement?

* had I written these scripts in bash, C# or C++, they would not have broken even remotely to the same degree. Of course these are not some completely unevolving entities either, however all take the promise of forwards compatibility deadly seriously, and it is more than possible to find 10-20 year old programs written in C++ or bash that continue functioning to the present day. From my perspective, they are therefore excellent and highly dependable tools.

Re:What If C++ Abandoned Backward Compatibility? by joshuamorton on Monday March 30, 2020 @07:54PM (#22733457)
I think in your rush to appear superior, you missed the much simpler explanation. Your first comment was easy to misunderstand:

> print vs print() is what I think the parent comment was referring to.

as another person mentioned is likely what you meant, but it was easy to take your comment as meaning that you had mismatched parens somewhere, which would imply broken python2, as well as 3.

> * given a tool that promises to cease functioning 'correctly' at any future moment based on its own whim, preferences, industry fashions and styles, in an ecosystem where many similar such tools exist that explicitly promise not to cease functioning over the same time period, it is a fool's errand to pick the tool that promises to externalize additional costs on the user when alternatives exist that avoid any such cost.

This is clearly a falsehood, if the tool provides additional value. To bring things back to the topic at hand, if C++ were allowed to break ABI compatibility in very specific ways, it could be faster. stl container types are slower than many third party ones (absl, for example).

Which is to say that if you want "the best" that C++ has to offer, you have to be willing to have your libraries make backwards incompatible changes.

To jump back to python,

> given tool designers who externalize almost frivolously minor technical costs on to every user, where each 'minor' change is amplified perhaps 10000 times over and directly translates into expensive engineering time

I disagree that this happened. The examples you give are trivially fixable with 2to3. There are harder problems that 2to3 doesn't solve, but it sounds like you don't have any, so the frivolously minor technical costs are frivolously minor, and translates into running `2to3 my_code/` one time, to fix all the missing parens and most of the moved functinos.

> bash that continue functioning to the present day

I have yet to encounter a 20 year old program written in bash that functions to this day. It might be syntactically valid, but it won't do what it intended to do.

Re:What If C++ Abandoned Backward Compatibility? by slovenlyrobot on Monday March 30, 2020 @11:52PM (#22734800)
I mistakenly thought you wanted clarity on my reasoning, instead it seems I've been made a fool of by providing an opportunity for you to argue a position I already understood and couldn't care less about. It's funny, this is also pretty much the reason I stopped relying on Python.

You're welcome to absorb all the externalized costs your heart desires, but in future please consider reviewing HN's rules before bandying attacks like "smug" and "superior".

Re:What If C++ Abandoned Backward Compatibility? by joshuamorton on Tuesday March 31, 2020 @01:59AM (#22735233)
Understanding ones views doesn't imply agreeing with them. A tool is only useful if, well, it's useful. A slow C++ is less useful than a fast one. So how is it that you can claim so strongly that the value from backwards compatibility is greater than the value from speed by default?

Bluntly, if I could break the ABI to get a 10% speed boost across the board, is that not worth it?

And I'm well aware of the site guidelines. I certainly don't think asking someone to tone down the holier-than-thou in their comments is a violation of them. Just the opposite, it's encouraged. So I'll continue to ask that you do so if you choose to respond.

Re:What If C++ Abandoned Backward Compatibility? by jjnoakes on Saturday March 28, 2020 @11:51PM (#22716229)
print vs print() is what I think the parent comment was referring to.
Re:What If C++ Abandoned Backward Compatibility? by mjevans on Saturday March 28, 2020 @05:56PM (#22714620)
The Unicode issue is one of the most painful sticking points. Handle legacy filesystems with the chance of filesystems that have previously valid (non / non \0 containing filenames) files in various encoding soup nightmares? Python3 is NOT the the tool for that job! Which means you can't write any systems tool stuff in Python3 because there's a good chance it'll blow up unexpectedly, or that you suddenly have to handle all sorts of things that in any other language you can just GIGO and move on.
Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Sunday March 29, 2020 @04:10AM (#22717238)
Python 3 promotes the most likely scenario: you are on a modern system with normal looking filenames.

It would be unwise to design an API that promotes a niche need like dealing with a legacy file system with corrupted file names. This is what Python 3 fixed, making the easy things easy, and the complicated things possible, not the other way around.

But Python 3 is absolutely up to the task of handling legacy file systems with random encoding mixed in, you just need to tell it explicitly you are doing so.

Let's create a file with a completely garbage name, made of random bytes, which is allowed on Unix:

    >>> import os, sys
    >>> sys.version_info          
    sys.version_info(major=3, minor=7, micro=5, releaselevel='final', serial=0)
    >>> with open(os.urandom(32), 'wb') as f: 
    ...     f.write(os.urandom(200)) 
If you pass bytes to any file system function, it will return file names as bytes:

    >>> filename = os.listdir(b'.')[0]
    >>> type(filename)
    <class 'bytes'>
    >>> filename[:10]   
    b'\xf8-U\xa5\x1dq\xad?\xbf\xa2'
And you can just open that:

    >>> data = open(filename, 'rb').read() 
    >>> data[:10]
    b'E\x05\xce*M \xf5\xfeK\x18'
    >>> type(data)
    <class 'bytes'>
You do exactly the same as what you did with Python 2, and treat the files as raw bytes entirely, without thinking about the content.

Some API in Python require text. If you want to pass the file names to those API, you can use surrogate escape, which let you convert back and forth between arbitrary bytes and utf8 text, without loosing information:

    >>> as_text = filename.decode('utf8', errors='surrogateescape')
    >>> as_text[:10]
    '\udcf8-U\udca5\x1dq\udcad?\udcbf\udca2'
    >>> type(as_text)
    <class 'str'>
    >>> as_text.encode('utf8',  errors='surrogateescape') == filename
    True
This is a good thing, it forces the dev to be explicit about the places in your code where you are dealing with a specific scenario. It also makes you pay the price of doing so opt in, not opt out.

If you have to do a robust version of this with Python 2, you will have to do that anyway: at some point mixed encoding will bite you if you don't have a neutral representation for them. Python 2 gave you the illusion of robustness, because it said "yes" to most operations.

I remember quite well that a lot of Python 2 programs didn't work in Europe because your user directory would contain your name, which could be non ascii. Python 2 programs are opt in to deal with it. It's the opposite philosophy, and caused so many crashes.

Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Sunday March 29, 2020 @06:22AM (#22717771)
I failed to mention that it's only useful to do this manually if you need to decode path with mixed encodings, or share said path with the rest of the world.

If all you need is to work with arbitrary mixed bags of file names, you can just pass "str", and Python will use automatically and transparently surrogateescape everywhere.

Re:What If C++ Abandoned Backward Compatibility? by afiori on Sunday March 29, 2020 @06:44AM (#22717871)
I think that the main complaint is that the early versions of python 3 had deep issues with this and it took years to fix them.
Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Sunday March 29, 2020 @07:51AM (#22718221)
The first versions of python 3 were indeed, not suitable for serious work. Python 3 started to be usable from 3.3, interesting from 3.4, comfortable from 3.5, and objectively way better than 2.7 from 3.6.

It's not a surprise, as most softwares need iterations to get get good. Python 2.7 has not started as the amazing tool it is now, and as I started my career with 2.4, you remember some funny stuff.

This is why Python 2.7 was kept around for 13 years after Python 3 first came out.

Now, 3.6 came out in 2016. It solves many issues 2.7 had, and add tons of goodies. It's very ergonomic, can be installed easily. It's a great software.

It's 2020, let's enjoy the goodness of Python 3.

Re:What If C++ Abandoned Backward Compatibility? by afiori on Sunday March 29, 2020 @11:27AM (#22719752)
But this is exactly why people keep piling on about python 3, as an "upgrade" it was worse than what tried to replace for 8 years.
Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Sunday March 29, 2020 @12:15PM (#22720140)
Sure.

And now it has been better for the last 5 years, and does solve the problems it intended to solve.

Re:What If C++ Abandoned Backward Compatibility? by afiori on Sunday March 29, 2020 @01:31PM (#22720790)
No one disputes that today's Python 3 is better that today's Python 2, especially for new projects. (A point can be made that Python 2 now is perfectly frozen in time and so 100% stable, but most people do not care that much)

The only thing this means is that the botched upgrade did not end up killing Python; it says nothing about whether it was done badly or not.

(I have nothing against python, I just believe it is important to understand why and how what happened happened to avoid similar errors in the future)

Re:What If C++ Abandoned Backward Compatibility? by afiori on Sunday March 29, 2020 @06:40AM (#22717844)
for a long time it was impossible to write code compatible with both python 2 and 3
Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Sunday March 29, 2020 @07:58AM (#22718262)
It started to be possible with Python 3.3, which came out 8 years ago.

We are at Python 3.8.

Python 3 has been around for 13 years, during which Python 2.7 was still supported.

Re:What If C++ Abandoned Backward Compatibility? by otabdeveloper2 on Saturday March 28, 2020 @06:59AM (#22710387)
> python is very expressive, hence the code base have way less numbers of lines than in C++

This doesn't match reality. In reality, many Python projects have way more lines of code than equivalent C++ projects. Probably because of the 'expressiveness' you cite; you can't really showcase your love of coding and job security though artificial complexity without 'expressive' bells and whistles. (This is the idea that lead to languages like Go, I'm pretty sure.)

That said, C++ is plenty 'expressive' itself.

Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Saturday March 28, 2020 @07:14AM (#22710427)
> many Python projects have way more lines of code than equivalent C++ projects.

That is mathematically impossible. Even if the syntaxes were exactly the same (which they are not, python syntax is on average shorter), the low level nature of C++ requires your code to do operations that Python does need to do, such as memory management.

It's like stating the sky is red.

Re:What If C++ Abandoned Backward Compatibility? by snovv_crash on Saturday March 28, 2020 @10:29AM (#22711329)
Once you've written sufficient unit tests to prove your code works as well as a C++ equivalent does just by compiling, I don't think Python ends up being more dense though.

I'd also argue that operator overloading etc lets C++ be just as expressive as Python, the libraries just need to be designed with that in mind.

Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Saturday March 28, 2020 @01:04PM (#22712441)
> Once you've written sufficient unit tests to prove your code works as well as a C++ equivalent does just by compiling

You mean in the same way C++ dev write tests to prove that all their code has no memory error which you get in Python for free ?

Except:

- tests are way shorter to write in python than in C++

- C++ devs often write zero tests for their code, just like python devs

- python duck typing + REPL means compiler checks are rarely necessary

- if you need to be type checks, you use type hints in python, which even then is still less verbose than c++

> I'd also argue that operator overloading etc lets C++ be just as expressive as Python, the libraries just need to be designed with that in mind.

Ok, let's say you have this json:

    [{
        "name": "Kévin",
        "age": 23,
        "hired": "2005-06-03 02:12:33",
        "emails": ["[email protected]", "[email protected]"]
    }, {
    }, {
        "name": "Joël",
        "age": 32,
        "hired": "2003-01-02 12:32:11",
        "emails": ["[email protected]", "[email protected]"]
    },
    ... other entries
    ]

It's very simple. Very basic. There is no trick in there: it's standard utf8, well formed, no missing value.

You want to print people details in alphabetical order this way:

    Joël (32) - 02/01/03:
    - [email protected]
    - [email protected]
    Kévin (23) - 03/06/05:
    - [email protected]
    - [email protected]
    ... other entries
This is a 1rst year of college exercise. Nothing remotely complicated. I'm not choosing some fancy machine learning or data processing stuff for which Python has magic libs. Every language can do that easily.

In Python 3.7, which is already 2 years old, the code would be:

    import json
    import datetime as dt

    with open("agenda.json") as fd:

        agenda = sorted(json.load(fd), key=lambda people: people["name"])

        for people in agenda:

            hired = dt.datetime.fromisoformat(people["hired"])
            print(f'{people["name"]} ({people["age"]}) - {hired:%d/%m/%y}:')

            for email in people["emails"]:
                print(f" - {email}")
The entire script is there. There is no trick. This is not a code golf version of of it; I could make it shorter. It really is standard Python. There is no 3rd party lib either.

It's not specific to Python, you would get this expressiveness with Ruby or Perl.

I don't see in which world you would get that in regular, honest to god, day to day, portable C++.

You have to declare types, many includes, you'll have headers and a main function. You have the memory and references to manage.

It doesn't make C++ a bad language.

It doesn't make python a better language.

The C++ version will take way less RAM than the Python version for example.

It's just the nature of those languages implies that.

Re:What If C++ Abandoned Backward Compatibility? by steveklabnik on Saturday March 28, 2020 @03:05PM (#22713501)
For fun, I whipped this up in Rust. I decided to go with an explicit struct to serialize it into, because it makes the error handling easier, and is a bit more idiomatic. I kept unwrap because it's similar to the python semantic of throwing an exception. It's pretty close though!

    use chrono::NaiveDateTime;
    use serde::*;
    use serde_json;
    
    #[derive(Deserialize)]
    struct Person {
        name: String,
        age: u32,
        hired: String,
        emails: Vec<String>,
    }
    
    fn main() {
        let data = std::fs::read_to_string("agenda.json").unwrap();
        let mut people: Vec<Person> = serde_json::from_str(data).unwrap();
    
        people.sort_by(|a, b| b.name.cmp(&a.name));
    
        for person in &people {
            let datetime = NaiveDateTime::parse_from_str(&person.hired, "%Y-%m-%d %H:%M:%S").unwrap();
            println!(
                "{} ({}) - {}",
                person.name,
                person.age,
                datetime.format("%d/%m/%y")
            );
    
            for email in &person.emails {
                println!(" - {}", email);
            }
        }
    }
Re:What If C++ Abandoned Backward Compatibility? by steveklabnik on Saturday March 28, 2020 @08:02PM (#22715254)
Apparently you can deserialize the date directly with serde and chrono too! So this could be even shorter.
Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Saturday March 28, 2020 @03:28PM (#22713703)
And Rust is very, very expressive and concise for a bare metal language. Serde is a beautiful thing.
Re:What If C++ Abandoned Backward Compatibility? by jcelerier on Saturday March 28, 2020 @04:42PM (#22714171)
It's a bit longer in C++ but frankly not by that much :

    #include <iostream>
    #include <sstream>
    #include <fstream>
    #include <iomanip>
    #include <nlohmann/json.hpp>
    #include <range/v3/action/sort.hpp>
    
    int main()
    {
      using namespace nlohmann;
      using namespace ranges;
    
      const json parsed = json::parse(std::ifstream("/tmp/json/test.json"));
    
      std::vector agenda(parsed.begin(), parsed.end());
      sort(agenda, {}, [] (const auto& j) { return j["name"]; });

      for(const auto& people : agenda) try {
        std::tm t{};
        std::istringstream(people["hired"].get<std::string>()) >> std::get_time(&t, "%Y-%m-%d %H:%M:%S");
    
        std::cout << people["name"] << " (" << people["age"] << ") - " << std::put_time(&t, "%d/%m/%y") << ": \n";
        for(const auto& email : people["emails"])
          std::cout << " - " << email << "\n";
      } catch (...) { }
    }
Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Saturday March 28, 2020 @05:58PM (#22714630)
This is getting ridiculous.

We went from:

> many Python projects have way more lines of code than equivalent C++ projects

To:

> It's a bit longer in C++ but frankly not by that much

With the proof being literally __twice__ more characters, with one line being more than a 100 characters long.

I understand that C++ doesn't have a native JSON lib, and sorting is a bit out there, but giving 3rd party lib access to Python feels like cheating:

    import pandas as pd
    agenda = pd.read_json("agenda.json", convert_dates=["hired"])
    for _, (name, age, hired, emails) in agenda.sort_values("name").iterrows():
        print(f"{name} ({age}) - {hired:%d/%m/%y}:")
        for email in emails:
            print(f" - {email}")
I mean, I can also create a lib that does the entire script, install it, and just do 'import answernh; answerhn.print_json("agenda.json")'

Now again, this is not so say "Python is better than C++". That's not the point.

If you want to write a game engine, C++ makes sense, verbosity doesn't matter, and you don't want the Python GC to kick in. If you want to iterate on your Saas product API quickly, it's probably not the best choice.

Why pretend otherwise? What the point of stating the sky is red?

Re:What If C++ Abandoned Backward Compatibility? by snovv_crash on Sunday March 29, 2020 @02:51PM (#22721494)
To be fair to the C++ version, you need to give as many guarantees from your code as C++ does from compiling. To me, in this case this is mainly the output formatting. Python won't tell you until runtime that you have a malformatted string, so add in some unit tests to make sure your string formatting won't crash, and you'll be at a similar number of lines of code as the C++ or Rust version.
Re:What If C++ Abandoned Backward Compatibility? by joshuamorton on Sunday March 29, 2020 @05:48PM (#22723076)
> Python won't tell you until runtime that you have a malformatted string

Neither will C++, as far as I know, or do you mean that the compiler will validate the formatting of the string literal (python has linters that will validate this too!).

Hell, even with statically verifiable types, the python is shorter.

Re:What If C++ Abandoned Backward Compatibility? by jcelerier on Monday March 30, 2020 @03:48AM (#22726026)
> Neither will C++, as far as I know, or do you mean that the compiler will validate the formatting of the string literal.

With iostreams there are no format strings so there is nothing to validate. Libraries such as https://github.com/fmtlib/fmt are allow to do compile-time parsing of the string though.

Re:What If C++ Abandoned Backward Compatibility? by detaro on Saturday March 28, 2020 @06:50PM (#22714898)
I think it shows quite well that the expressiveness difference is not as a large as many would think.

Also, the difference in tone towards jcelerier compared to steveklabnik seems not warranted here. Both IMHO contributed an educational example. Your response here equally does (or does not) apply to the Rust version, doesn't it?

Re:What If C++ Abandoned Backward Compatibility? by BiteCode_dev on Sunday March 29, 2020 @04:11AM (#22717242)
Rust is fantastically expressive for a low level language.

And modern C++ is not 15 years old C++. You have auto, lambda, etc. I just think it's silly to try to pretend to be more expressive than scripting languages.

It's like Schwarzenegger trying to pretend it's as flexible as gymnast. What for? The guy is amazing at what he does.

Re:What If C++ Abandoned Backward Compatibility? by jcelerier on Monday March 30, 2020 @04:02AM (#22726090)
> I just think it's silly to try to pretend to be more expressive than scripting languages.

So far we have a Python, a Rust and a C++ program in this thread which output the same thing given the same input, which, by the definition of expressive power of programming languages means that they are exactly as expressive as each other (given this information only and notwithstanding small differences such as error handling in this case).

Also you mentioned in your original thread :

> Even if the syntaxes were exactly the same (which they are not, python syntax is on average shorter)

indeed

> the low level nature of C++ requires your code to do operations that Python does need to do, such as memory management.

Notice that there is nothing which looks like memory management in my code. There are entire classes of programs that can be written without thinking about when to allocate or free your memory at all - just declare your variables on the stack and with std types, and that is handled for you (and that's not a modern C++ thing ! it's been like that since the very beginning). Opting in to memory management is an active, conscious effort in these cases (or a residue of people who only were taught java / c# at school and sprinkle their code with `new`).

Re:What If C++ Abandoned Backward Compatibility? by SaxonRobber on Saturday March 28, 2020 @05:02PM (#22714310)
It also requires a library outside of the standard.
Re:What If C++ Abandoned Backward Compatibility? by rfoo on Saturday March 28, 2020 @05:50PM (#22714579)
Java and Perl does not have json in builtin libs, does it make Java/Perl less useful or less expressive than Python?
Re:What If C++ Abandoned Backward Compatibility? by steveklabnik on Saturday March 28, 2020 @07:25PM (#22715102)
To be clear, my solution also included two libraries outside of the standard library. That’s idiomatic for Rust.
Re:What If C++ Abandoned Backward Compatibility? by jcelerier on Saturday March 28, 2020 @05:06PM (#22714328)
does that matter ? Python does not even have an ISO standard
Re:What If C++ Abandoned Backward Compatibility? by SaxonRobber on Saturday March 28, 2020 @05:15PM (#22714387)
I think it does, I should not require an external dependency for JSON. Having standard JSON support is far far more useful than another micro optimizations.
Re:What If C++ Abandoned Backward Compatibility? by jcelerier on Saturday March 28, 2020 @05:46PM (#22714559)
fifteen years ago that would have been XML and twenty-five years ago SGML and in ten years it'll be TOML or protobuf or something so...
Re:What If C++ Abandoned Backward Compatibility? by SaxonRobber on Saturday March 28, 2020 @05:52PM (#22714594)
Eventual deprecation is not a valid justification for making current technology less useful.

Now I would buy your argument if C++ were as conservative as C, but it clearly isn’t. It keeps trying to push itself as a modern general purpose language, while ignoring what it actually takes to be useful as one.

Re:What If C++ Abandoned Backward Compatibility? by otabdeveloper2 on Wednesday April 01, 2020 @03:26AM (#22746511)
The original post was about 'projects', not code snippets.

If you've done any serious (large, long, multi-team) projects in a dynamically-typed language, you know how quickly they turn into a big ball of mud where you're spending more time refactoring your refactorings than writing useful code.

Re:What If C++ Abandoned Backward Compatibility? by santamarias on Saturday March 28, 2020 @05:42AM (#22710173)
I agree about the "rocky transition" from Python 2 to 3. Still if the Python migration story gives any inference towards the outcome of an eventual C++ transition, the new language would be an even more massive success; it seems that Python 3.x is doing alright right?
Re:What If C++ Abandoned Backward Compatibility? by roenxi on Saturday March 28, 2020 @05:58AM (#22710220)
That is somewhere in the logical region of saying 'Stephen Hawking was really smart, maybe amyotrophic lateral sclerosis is a good thing'. The transition to Python 3 was not pretty. Still isn't; Python 2 documentation features prominently when I'm trying to look up information.

The to abandon backwards compatibility in C++ is to make a mockery even of the name of the language (see the "C" in there). If they want to create a new language they should call it something different. Willfully abandoning backwards compatibility and keeping the name is an abuse of one of the great brands in software.

Re:What If C++ Abandoned Backward Compatibility? by santamarias on Saturday March 28, 2020 @07:12AM (#22710422)
I was just trying to get a response to how the Python transition mentioned was so (edit:) "catastrophic". I don't understand the need to bring fiction writers, fatal diseases or laden words like "mockery" or "abuse" to the debate.
Re:What If C++ Abandoned Backward Compatibility? by ComputerGuru on Saturday March 28, 2020 @08:12AM (#22710648)
Stephen Hawking was not a fiction writer. Stephen King does not have a horrible disease.
Re:What If C++ Abandoned Backward Compatibility? by santamarias on Saturday March 28, 2020 @08:22AM (#22710695)
sorry, my bad
Re:What If C++ Abandoned Backward Compatibility? by bsder on Saturday March 28, 2020 @04:50PM (#22714223)
> Python 2 documentation features prominently when I'm trying to look up information.

I consider this more a case of the ossification of search.

Neither search engines nor specific sites like Stack Overflow deal with the fact that information can switch from right to wrong with age.

Re:What If C++ Abandoned Backward Compatibility? by tempay on Saturday March 28, 2020 @06:01AM (#22710229)
Yeah, I think Python 2 has been successfully killed at this point. There are a decent number of projects which still need to migrate (and I recently became responsible for a couple) but it’s been a long time since I heard anyone claim they can keep Python 2 forever. The maintenance burden of keeping Python 2 is rapidly increasing as libraires drop support.
Re:What If C++ Abandoned Backward Compatibility? by pletnes on Saturday March 28, 2020 @06:44AM (#22710358)
Since python3 has many more users than python2 this is not a relevant comparison. It was not smooth, but now it’s done and it worked. There have been many C++ forks which have failed to replace it, e.g D, Rust, ...
Re:What If C++ Abandoned Backward Compatibility? by MaxBarraclough on Saturday March 28, 2020 @07:00AM (#22710390)
D and Rust are not forks of C++, they're entirely different languages.
Re:What If C++ Abandoned Backward Compatibility? by amelius on Saturday March 28, 2020 @06:25AM (#22710312)
> One of the main reasons to stick with C++ (and C) is that the investment you put in the code you're writing right now, no matter how fugly it is, will be there and keep working in the future.

Except slowly people will be writing parts of it in Rust, or they would be using libraries written in Rust (because availability), and then after a while people get annoyed of using more than one language and the whole project will be rewritten in Rust. Of course, at that point, a new language will be invented and Rust code will be looked at as rusty :)

Re:What If C++ Abandoned Backward Compatibility? by kllrnohj on Saturday March 28, 2020 @03:59PM (#22713896)
Rewriting parts in Rust would require Rust to have good C++ interop, which it doesn't. At all. Rust has good C interop, so if your code is already divided into C-abi shared libraries then you're golden. But if it's not then Rust migration really isn't an option.

And realistically I'm not entirely sure how you can add C++ interop to Rust without also ruining Rust. It's a hard problem to say the least.

Re:What If C++ Abandoned Backward Compatibility? by bsder on Saturday March 28, 2020 @04:50PM (#22714234)
Does anything have good C++ interop?
Re:What If C++ Abandoned Backward Compatibility? by pjmlp on Saturday March 28, 2020 @06:41PM (#22714844)
D, .NET and COM/UWP.
Re:What If C++ Abandoned Backward Compatibility? by otabdeveloper2 on Saturday March 28, 2020 @07:01AM (#22710391)
> Except slowly people will be writing parts of it in Rust

Wishful thinking.

Re:What If C++ Abandoned Backward Compatibility? by pjmlp on Saturday March 28, 2020 @07:18AM (#22710438)
Re:What If C++ Abandoned Backward Compatibility? by fctorial on Saturday March 28, 2020 @07:16AM (#22710432)
> see how the recent Half-Life Alyx can trace its codebase back to Quake 1

Source?

Re:What If C++ Abandoned Backward Compatibility? by garblegarble on Saturday March 28, 2020 @08:39AM (#22710769)
Half Life Alyx is built on Source 2, which was extended from Source 1, which is a heavily modified version of GoldSrc which was based on the Quake 1 engine.

John Carmack said in 2004 that "there are still bits of early Quake code in Half-Life 2" - https://github.com/ESWAT/john-carmack-plan-archive/blob/mast...

https://en.wikipedia.org/wiki/Source_2

Re:What If C++ Abandoned Backward Compatibility? by badsectoracula on Saturday March 28, 2020 @08:40AM (#22710774)
Yes :-P.

In all seriousness, Half-Life Alyx is based on Source 2 which itself is based on Source 1 which is based on GoldSrc which is based on Quake 1.