Hacker Newsnew | past | comments | ask | show | jobs | submit | cherryteastain's commentslogin

Why would you jump through all these hoops instead of just writing C++ if you want "C with generics"

Because some people really hate C++ to their bones, hence this kind of stuff that keeps coming up.

I was really disappointed that Microsoft decided to backtrack on C++'s is the future, after the new found Linux and FOSS love.

https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-an...

https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-...

Not that it matters much, as nowadays C and C++ have a new policy at Microsoft due to goverments and cyberlaws.

https://azure.microsoft.com/en-us/blog/microsoft-azure-secur...

https://blogs.windows.com/windowsexperience/2024/11/19/windo...


because i work on a legacy project that is coupled to safety regulations and other quality guarantees, and we cannot just simply roll out a solution ported to c++ on the next release, or even tenth, so perhaps we make it work until we can.

however we can set a standard and expectation for new projects to use c++, and we do and set an expectation to target a specific std.

i see this sentiment quite a lot on hackernews -- feels like a lot of people saying "git gud" -- i would expect a lot more nuance applied here.


Because for many of the use cases where C is used, switching to C++ involves jumping through even more hoops.

Do you have a couple of real world examples?

Any established C codebase, for example the kernel or Postgres?

Traditionally microcontroller firmwares as well, though those are increasingly friendly to C++, you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.


> Any established C codebase, for example the kernel or Postgres?

Obviously you mean the Linux kernel, specifically. Also C++ has gotten a lot better since 2003 and before.

Examples of C++ usage in commercial codebases:

- anything Nintendo has written since 2010 (including microkernel, entire OS and all, for 3DS and Switch 1/2)

- well-known, high performing databases like ScyllaDB

> you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.

With the exception of exceptions (and coroutines but that's easily customizable), it's merely a standard library thing and doesn't affect language features (incl. language features exposed as std:: funcs/traits)

C++ has got a bad rep because it never fixes broken stdlib parts due to API and ABI concerns, and has many footguns due to this, that might make Rust and C better choices in corporate environments. However, IMHO, C++ is a much better language than C for personal projects, or when having a team of experienced folks.


Nothing is stopping you from linking C++ code to Postgres.

I'm not sure about other compilers, but compiling C code as C++ with MSVC ends up with pretty much the exact same code, instruction by instruction. C++ is a bit more strict though especially with casting, so a lot of code won't compile out of the box.

C++ code compiles to a different function names in object file (name mangling). You probably need to put a lot of ugly `#ifdef __cplusplus extern "C" {` boilerplate in your headers, otherwise C and C++ files will not compile together.

Don't forget the infamous pattern used in some C projects too:

  struct foo decl = {
    .member = /* ... */
    .next = &(struct nested_pointer) {
        .nested_member = /* ... */,
    },
    .array = (struct nested_array[]) {
      [0] = { /* ... */ },
    }
  };
This pattern does not work in C++ as the nested declarations become temporaries.

literally a good majority of existing embedded software coupled to applications in safety -- devices used by fire safety and first responders.

Embedded systems, for example.

I know it used to be, but is it really still common for embedded systems to use weird architectures that G++/Clang don't support?

Unless it is a popular system or common architecture, yes.

Could you show me an example of a micro controller still supported today which doesn't have a C++ compiler?

The 8051. I think C++ compilers technically exist for it, but for most hardware the only practical choice is the Keil C51 compiler, which is C89.

> is it common for weird architectures to exist?

> yes, unless you're using a common one.


Writing extensions for projects that support C extensions but may not support C++ extensions, e.g. many dynamic languages.

You can still write the extension in C++ and expose an extern "C" interface.

That's possible, but then the people building your extension need a C++ toolchain.

The question was "please provide examples where switching to C++ involves jumping through even more hoops", and in my view requiring downstream to use a C++ environment when they're expecting to use a C environment qualifies.


True. For me, C++ itself is the maze of hoops I would rather want to avoid.

The real answer: it's more fun this way.

Why would you write C++ if you can get the same result by jumping through a few hoops with C?

Templates in C++ require language support - you can't simply implement them with "a few hoops" in C.

Templates are a solution for a problem that c++ themselves created

You mean the same problem that the article is trying to solve in C? Generic data structures?

What problem?

> What are the base cases? A base case is an ancestor whose Britishness does not depend on a parent, e.g. someone who was naturalised, or born in the UK before 1983 (which makes one unconditionally british regardless of parents). That's right, further into the future we get from 1983, the taller these call-stacks can get.

This is insane to me, coming from a country that simply has a central database of all citizens and foreign residents, and a citizenship check is probably something like a single SELECT on an SQL table.


Many countries simply have no way of knowing who their citizens are.

People born abroad are often citizens.

The British have had an insane number of changes in territory that affect citizenship.

Some of their current citizens have citizenship because they were born in Bombay (Mumbai). Others because they were born in Hong Kong.

Maintaining a reliable list of citizens requires regular registration, and loosing citizenship if you don’t register.


Even in that case it would probably enough to prove your citizenship once to get into the database.

It would have to be combine with other databases. A death index, at the least.

> citizenship check is probably something like a single SELECT on an SQL table

I am willing to bet, with extremely unfavorable odds to me, that is not true



Is gccgo really faster? Last time I looked it looked like it was abandoned (stuck at go 1.18, had no generics support) and was not really faster than the "actual" compiler.

Digging around, looks like it's workload dependent.

For pure computational workloads, it'll be faster. However, anything with heavy allocation will suffer as apparently the gccgo GC and GC related optimizations aren't as good as cgo's.


As of about five years ago gccgo was slower for almost all workloads: https://meltware.com/2019/01/16/gccgo-benchmarks-2019.html

If we're cherrypicking like that I'm sure you can find some Japanese prefecture or Swiss canton that has 10 years+ higher life expectancy than Hawaii's 79.9 years, the US state with the longest life expectancy.

Almost every US State is larger than Switzerland -- the entire country -- never mind a single canton. If you want to get that granular some State counties have life expectancies in the mid-90s.

I think a subnational analysis of Switzerland is a good metric for analyzing subnational development in similarly sized states like MA, Kansas, Minnesota, and Mississippi.

At a macro-level or even for larger states of the US like California or Texas, not really.


My reply is beside the point, but here's the life expectancy per canton of Switzerland: https://ind.obsan.admin.ch/indicator/obsan/lebenserwartung

I think of the okinawa centenarian study...

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


I thought that had been discounted, as with many of the Blue Zone studies.

Due to birth records being lost in war time bombing, I just need to find a citation to support this beyond that of a few podcasts.

Værsgo:

https://www.ucl.ac.uk/ioe/news/2024/sep/ucl-demographers-wor...

https://theconversation.com/the-data-on-extreme-human-ageing...

Discussed here 9 months ago:

https://news.ycombinator.com/item?id=41597415

Reddit discussion seems to tackle this research more critically:

https://old.reddit.com/r/longevity/comments/1fhcfvu/the_data...


The blue zone debunking was done by somebody outside of this field of study. The actual researchers who did the on the ground work to verify ages aren't so foolish as to just blanket ignore this sort of thing. Verification is more complex than "ask Bob how old he is and write it down."

"Blue zones as health miracle" is overstated. "Blue zones as simple fraud" is overstated.


>Okinawa in Japan is one of these zones. There was a Japanese government review in 2010, which found that 82% of the people aged over 100 in Japan turned out to be dead. The secret to living to 110 was, don’t register your death. (conversation article)

sounds fairly fraudy.


None of the blue zones from the actual research are cities this large. And the researchers that identified the blue zones did not get their data from government census information.

You absolutely should do the same spatial inequality analysis in Japan and Italy as well (in fact, this is the norm in Italy's policymaking space due to the documented north-south divide). Heck, this is called out in the Nature article as well if you read TFA.

The US (330m), Japan (120m), and Italy (60m) are all large countries, and in the US and Italy's case, extremely federalized with social service delivery responsibilities falling onto subnational governments.

And for large developed countries like the US, UK, France, Germany, Italy, Japan, etc their developmental indicators have largely converged at a macro-level (the difference in living standards between countries with a national HDI of 0.900, 0.920, and 0.940 are marginal), but spatial inequality continues to act as a persistent laggard.

Outliers matter. This is like statistics/EDA 101.

P.S. If you do EDA on Japan versus US from an HDI perspective, you find that the Southern Kanto region (ie. Greater Tokyo) tends to skew Japanese statistics - with a subnational HDI comparable to MA - but the rest of the subnational regions of Japan have HDIs comparable to Tennessee (0.890-0.900) or Florida (0.920-0.930).

What this highlights is that public service delivery is stronger in the Greater Tokyo region than the rest of Japan.

And this is unsurprisingly a major topic of discussion in Japanese policymaking as well, as the poorer regions have seen a massive youth flight to Tokyo.

Same with the less developed regions of the US as well.

When you do a similar spatial analysis of the US, you find the Deep South (MS, AL, AR, LA), Appalachia (WV, TN, KY), and MO continuing to lag. You also end up identifying rust belt states like MI and OH starting to lag.

The interest thing is, the Deep South and Appalachia didn't seem to lag in the early 1990s compared to the rest of the states, but remained stuck at 1990s levels while other states improved significantly in the 2000s and 2010s, and it was these states that regressed the most in the COVID years (2020-2022) [0]. My running theory is that these states were the kinds of states where low value single factory/industry towns (eg. Textiles) were most prominent, and were the worst hit by a mixture of NAFTA, China Shock, and the Great Recession.

This would also explain why GA, NC, and SC didn't see the same laggardness despite being comparable with the rest of the south in the 1990s - Atlanta, Charlotte, RTP, Greenville, and Columbia were industrialized enough in high value industries like automotive and power systems and had significant additional industries like Finance and Tech that allowed them to upskill and diversify.

[0] - https://globaldatalab.org/shdi/table/healthindex/USA/?levels...


> We’ve rebuilt the web like an air traffic control system – just to serve a few kilobytes of text.

Funny, in the context of Germany's ATC working off some Emacs Lisp cooked up by one dude in just a week back in the 90s [1]

[1] https://old.reddit.com/r/emacs/comments/lly7po/do_you_use_em...


I agree that it's unnecessary, and Python's success despite not having private members/fields is testament to that. But public/private fields/methods, like pretty much everything in OOP, is a 'social' rather than engineering innovation. Just as a class tells you certain operations and data are inter-related, private methods or fields signal to a class's users that you probably will break things if you interfere with certain parts.

Otherwise, at least in C++, you can often bypass the private specifier without much difficulty. Perhaps the laziest and easiest way to do so is

    #define private public
    #include "foo.hpp"
    #undef private

You should safely shoot yourself in the foot with `friend`, which is a core language feature for accessing private members/functions/etc.

https://www.cppreference.com/w/cpp/language/friend.html

Redefining public as private can violate the ODR rule and triggers undefined behaviour because private members are ordered in memory in an undefined way, while public members are ordered in a standard way.


Python absolutely does have private members. If a member starts with two underscores, its class name (and an underscore) is prefixed to the member name, essentially resulting in the same behavior as a private modifier. (Although there are ways to circumvent this in Python, there are also ways to access private fields in most other languages.)

But even if that were true, that wouldn't mean that accessibility modifiers are unnecessary in other languages. Python is a certain language with certain idioms, and other languages are more or less OOP and hence some constructs that might not make sense in Python definitely make sense elsewhere.


No, it doesn't: double underscore field names are mangled basically to avoid easy overriding in su classes; keep in mind that it is a feature that predates super() in almost any form

I see what you mean what I wouldn't really qualify name mangling as private members, you're discouraged to access them but you can access them all the same.

I'd consider it the same, personally. It's a social contract that you can absolutely break if you want, just with a bit of work.

Less work in Python than it is Java, but there are ways to get to them in Java, or hell, just modify the source and change it directly. By doing that, you're doing something the developer didn't intend and you shouldn't be surprised if it doesn't work at some point in the future. Same as I'd expect in the Python case.


Sure, I think the bar to modify is higher in Java for example but I can't really find fault in what you're saying because I'd never unknowingly modify a member with double underscores in Python.

    > but you can access them all the same
Can't you do the same in C++ using struct offsets and reinterpret_cast<>? I'm not sure what you are saying here.

I'm not familiar with C++ enough to know about circumventing `private` but in Python you can access "private" members just like any other "public" ones, with the dot notation. There's no specific enforcement at the language level, no error will be thrown.

Something something undefined behavior

Not only are those not technically private, they were never intended for information hiding in the first place. Name mangling was introduced to avoid namespace conflicts in inheritance scenarios.

That is absolutely a social construct and not a language feature. You can override “private” members just fine with a simple assignment.

#define duck_season wabbit_season

#include "shoot.hpp"


The #define private public hack doesn't work reliably in modern C++ compilers and violates the One Definition Rule, potentially causing undefined behavior and hard-to-debug errors.

Actually, it won't compile in msvc (the linking phase, to be precise), MSVC uses different names for methods with different visibilities

I’ve seen a ton of this “#define private public” in a previous team that was forced to write unit tests in a rush due to the whims of leadership. It hurt to see, and the resulting white box tests were useless.

That #define trick is not valid due to how C++ groups members of different visibility classes together. See e.g. https://stackoverflow.com/a/36149568 It will work until it doesn't.

Don't do that in C++. Maybe unless if you are debugging. This can blow up in your face in unexpected ways.

> but we don't go around throwing such accusations at them

Simply not true. There is plenty of rhetoric about immigrants (even 2nd gen+) in Western countries being accused of being disloyal to their Western citizenship in favor of their ethnic origin countries. Chinese, Indians, Middle Easterners, Latin Americans etc are all accused of this; see the recent riots in LA for a very recent example. Yet this insinuation is made illegal only with respect to one country only for whatever reason.


[flagged]


> This insinuation really is only made to Jewish people

Certainly is news to japanese americans ( literally put in concentration camps ), chinese americans, german americans, mexican americans, arab americans, italian americans, catholics in general, indian americans, russian americans, etc.

> so of course they are more aligned with their country than ours, even if they have no direct ties to it whatsoever.

But there are plenty of jewish americans who are pro-israel. Such as jewish americans who joined the israeli military rather than american military.

It doesn't help that jewish americans were the main proponent to allowing dual citizenship in the US.


> This insinuation really is only made to Jewish people

This is untrue. It's untrue to such an extraordinary degree that it's hard to believe you're arguing in good faith.

Accusing people of being loyal to some other nation or cause is levied regularly against almost all peoples to some degree or other, particularly if the person holds any ancestral pride or accoutrements. Even just refusing to adapt to food customs is enough to arouse suspicions.

Look at the outrage about the "invasion" because some protestors hoisted Mexican flags. Various members of Trump's administration declared this a demonstration of "occupied" territories.

If you're Chinese in America you must never, ever, show an iota of association with your homeland -- or even just your grandparents home if you're 3rd generation -- or you will be ostracized and considered a deep agent. An Indian that has an Indian flag in their bio or the like is going to be frequently asked why they don't move back if they "love it so much".

Similarly, a frequent criticism of some Muslims is din wa dawla, which is a belief that religion and politics/the state are one. Indeed, if someone has religious beliefs that can go in conflict with the needs/goals of the state, there is a discord there that needs to be considered.

There are Americans who are more loyal to Israel than the US. Like, they will literally tell you this without an ounce of compunction or question (which is utterly verboten among virtually any other group. Similarly a US congressman wore his IDF uniform into congress, which is simply insane). On the flip side, there are many Jewish Americans who are deeply critical of Israel. Like does anyone think Bernie is a deep agent of Israel? Bernie, like much of Jewish America, is deeply critical of Israel.


Neither India nor China allow dual citizenship, so a US citizen of Indian or Chinese origin who argues in favor of one or the other at the expense of the US's strategic goals is absolutely suspect.

> Look at the outrage about the "invasion" because some protestors hoisted Mexican flags

Because LA Chicanos did not realize how inflammatory using the Mexican flag is in anti-government protests outside the California.

In CA, it's well understood it's used as an identity marker (though still exclusionary, as a growing portion of the Hispanic community in CA isn't Mexican anymore), but outside CA using another country's flag at the expense of the US absolutely is viewed as a severe faux pas.


>so a US citizen of Indian or Chinese origin who argues in favor of one or the other at the expense of the US's strategic goals is absolutely suspect.

To be completely clear, what you are saying is that a US citizen -- I have no idea what the relevance of foreign citizenship means, unless you're saying that everyone with a foreign citizenship is suspect -- of Indian or Chinese origin cannot have an opinion on anything. On foreign wars. On immigration levels or sources of intake. On government structure or laws or budgetary spending. Because literally anything can be cast by some hate monger as being at the "expense of the US's strategic goals".

Let's just be completely clear about your position here.

>but outside CA using another country's flag at the expense of the US

What does "at the expense" mean? People are protesting masked groups of thugs kidnapping people and renditioning them (illegally) to foreign gulags, and that is absolutely in the service of the US.

Though there have been a number of pro-Israel protests that are nothing but a sea of Israeli flags. Jim Jordan hilariously said "We fly the American flag in America", while he has a giant Israeli flag festooned outside his office. There is zero consistency about this "who gets to be proud of their heritage / fly a foreign flag" position beyond "who should be cowed and shut their dirty migrant faces".


> There is zero consistency about this "who gets to be proud of their heritage / fly a foreign flag" position beyond "who should be cowed and shut their dirty migrant faces".

There is >0 consistency, check skin color.


Kids until they are 18 can be dual citizen of China and American, they just have to decide at 18 which one to renounce. Also, attractive female snow boarders are also allowed dual citizenship but those are exceptions.

> Kids until they are 18 can be dual citizen of China and American, they just have to decide at 18 which one to renounce

True! But kids under 18 aren't voters not supposed to be a part of the political process, so any opinions they may have is moot.

> Also, attractive female snow boarders are also allowed dual citizenship but those are exceptions.

Yep! Plenty of exceptions all around if you are important enough or related to someone important enough.


> Neither India nor China allow dual citizenship

You can have dual citizenship if your Chinese citizenship is of the Hong Kong/Macao flavor


Getting HK or Macao PR is almost impossible - you have a better shot getting Shanghai or Beijing hukou. It's also a grey area - dual nationality is "permitted", not "allowed", and this policy can easily be revoked given how unstable HKSAR and Macau's governments have become

As such, it is an edge case or rounding error - especially in the Chinese American community. With the amount of effort it takes to get HK citizenship, you may as well take Canadian or American citizenship and try to break Chinese nationality law by lying about not having American citizenship (but they are cracking down on this)


Get your point but Disagree. Antisemitism is singular and has a long history that is well documented. You can see clearly that it isn’t just another instance of racism or xenophobia, but something different. Nobody accuses AOC of secretly working for Mexican government. See the difference?

I'm clearly not disputing the existence of antisemitism (or that it is a widespread scourge), and it isn't some trump card in a discussion like this. Someone claimed that only Jews are accused of split loyalties and that is insanely untrue.

"Nobody accuses AOC of secretly working for Mexican government"

It would be an incredibly weird accusation given that her ancestry is Puerto Rican.

And FWIW, there is a credible observation that the US evangelical "death cult" right has a bizarre, self-sabotaging loyalty to Israel. This group is not remotely Jewish, but they -- again not Jews -- are the reason the US government is subservient and in the service of Israel. All because their mythology holds Israel as some end times revelations battleground or some other bizarrely ignorant, archaic belief.


> Look at the outrage about the "invasion" because some protestors hoisted Mexican flags

The invasion angle is simply entering a country without permission. Protesting against the laws of the country while holding the foreign flag adds to the poor optics but the root of the invading accusation is the people actually invading.


All racism has group specific aspects. Start curbing freedom of speech in this manner and soon you will have a list of thousands of things you are not allowed to say, at which point we can't say we have freedom of speech anymore.

It was used against Americans of Japanese descent. They were actually locked up in concentration camps.

> who have literally never been to Israel, have no family who have been there, and have no recent ancestry even in the area

But are somehow—without any apparent reason, given that nothing binds them to the country—in favor of Israel being allowed to continue their war of agression against pretty much everyone around.


And this is bad for everyone except US gigacorporations how?

It is the US when promoting the industry and « the West » when trying to generate external support.

Substituting « the US » for « the West » on HN clarifies a lot of things.

I would rather we stop talking about the West, it does not mean much anymore.


It's definitely behind Waymo level, but the selling point of Tesla FSD is apparently that it works with 'normal' cameras as opposed to the super expensive Waymo kit so they can afford to put it in an upper mid range car.

I've seen it action only in my friend's Tesla in SF, and he also had to manually intervene, but to be fair Tesla themselves say you must be ready to take the wheel at any time. I think it may reach fully autonomous level with a few more years in the oven though.


> It's definitely behind Waymo level, but the selling point of Tesla FSD is apparently that it works with 'normal' cameras as opposed to the super expensive Waymo kit so they can afford to put it in an upper mid range car.

A potential problem for Tesla is prices are coming down for expensive sensors like LiDAR. We are at the point where you don't have to go camera only to keep a car affordable.

BYD is putting a dozen cameras, 5 mm-wave radars, and 12 ultrasound sensors on many of their cheaper cars. Go up to around Tesla's price and BYD has models with all those sensors and LiDAR.


> I think it may reach fully autonomous level with a few more years in the oven though.

The problem is Tesla pumps have been saying this for 10 years.


> I think it may reach fully autonomous level with a few more years in the oven though.

The article is about Tesla planning to launch it as 'autonomous' (mostly) driving _next week_.


You can instead install a FOSS fork of Signal like Molly [1] built by F-Droid directly from the source code

[1] https://molly.im/


Isn’t that against Signal’s terms of service? Won’t they ban you?


It is neither against the signal software’s license, nor it is against the signal service’s terms of service.

This is a false meme spread because the Signal founder (who is no longer with the company) didn’t like people making forks without changing the API server URL and running their own servers.

Open source software doesn’t work like that, however.


Whether they’re open source doesn’t matter (for this question). They control (their instance of) the server.

As you say, I do remember them issuing some threats about it, so it would be interesting to know if they’ve changed their stance on this.

(Discord, as an example, has banned users for using alternative clients.)


Alternative clients are banned in the Discord TOS. The Signal TOS is on their website and doesn’t prohibit any clients.

Also, separately, the idea that you can only use a service with a certain client is dumb.

Imagine if a website said you can only use a certain browser, or they ban you. It’s ridiculous.


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: