Hacker News new | past | comments | ask | show | jobs | submit | variadix's comments login

I would really like to see some exploration of alternative site structures, ways to design new social media sites with better systems of incentives, for users and for mods. There is very little diversity in how social media sites are driven by users and moderated by admins (engagement or vote driven post recommendations, opaque administration decisions). I think a small fixed cost per post paid in XMR has potential to significantly improve post quality for anonymous platforms. Moderation is trickier, especially if the owner doesn’t take a back seat and rein in the mods occasionally, but more transparency into moderators and their moderation decisions (public ban log with detailed justification, pseudo anonymous account tracking per mod) with some accountability from the user base e.g. meta discussion board around site policy with engagement from mods and owner.

This is so hilariously reductive it reads like satire. As if someone’s life experience can be deduced from their immutable characteristics.

Yes, congratulations, you've understood why it's extremely difficult. Well done.

I suppose next you'll tell me that either you don't understand it so it shouldn't be done or that because it's hard people should give up.


Your argument dropped something - the self selecting applicant pool for Harvard.

I haven’t worked with ffmpeg’s code, but I have worked with QEMU. QEMU has a lot of OOP (implemented in C obviously) that is supported by macros and GCC extensions. I definitely think it would have been better (and the code would be easier to work with) to use C++ rather than roll your own object model in C, but QEMU is quite old so it’s somewhat understandable. I say that as someone who mostly writes C and generally doesn’t like using C++.


What's the reason for ffmpeg to use C, also historic?


Fabrice also wrote the Tiny C compiler, so very much his language of choice ..

For those used to the language it was seen as "lighter" and easier to add OO like abstractions to your C usage than bog down in the weight and inconsistencies of (early) C++

https://bellard.org/

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


> weight and inconsistencies of (early) C++

Since very little is ever removed from C++, all the inconsistencies in C++ are still there.


Every language has inconsistencies, and C is not stranger to that. Much of c++’s baggage is due to C and you carry the same weight. That’s not to say that initialization isn’t broken in C++, but just like many features in many languages (off the top of my head in C - strcpy, sprintf, ctime are like hand grenades with the pin pre pulled for you) don’t use them. There’s a subset of C++17 that to me solves so many issues with C and C++ that it just makes sense to use. An example from a codebase I spend a lot of time in is

    int val;
    bool valueSet = getFoo(&val);
    if (valueSet) {}
    printf(“%d”, val); // oops
The bug can be avoided entirely with C++

    if (int val; getFoo(&val)) // if you control getFoo this could be a reference which makes the null check in getFoo a compile time check
    {}
    printf(“%d”, val); // this doesn’t compile.


For C users. And C++ users:

In C++ we can declare variable in the while or if statement:

https://en.cppreference.com/w/cpp/language/while

https://en.cppreference.com/w/cpp/language/if

It's value is the value of the decision. This is not possible with C [1].

Since C++17 the if condition can contain an initializer: Ctrl+F if statements with initializer

https://en.cppreference.com/w/cpp/language/if

Which sounds like the same? Now you can declare a variable and it value is not directly evaluated, you also can compare it in a condition. I think both are neat features of C++, without adding complexity.

[1] Also not possible with Java.


Declaring a variable in a loop or if statement is supported since C99: https://en.wikipedia.org/wiki/C99

Also in Java: https://www.geeksforgeeks.org/for-loop-java-important-points...


Regarding Java:

It is possible that you confuse while- and for statements?


No, declaring a variable in a `for` loop is supported in C99 but you can't do if-init.


You do :)

My post was about while and if and you repeatingly bring up for. The for statement is another statement.


Ah, you're right (finally tried it out). But it 100% works in a loop (usually for loop)


It’s one of those things that I never knew I wanted until I started using it, and now i miss it when it’s not available.The reason you want it is the same reason you want to declare a variable in the statement of a for loop rather than pre declaring and using a while loop


I've used it in go a lot. If you want to kludge it, you can still put a block around the if. But it's not nearly as nice


You could write this in C, no?

  { int val; if (getFoo(&val)) {
    ...
  }}
Both ways of expressing this are weird, but stating that this can't be achieved with C is dishonest in my opinion.


If I reformat this,

    {
        int val; 
        if (getFoo(&val)) {
    
        }
        printf("%d", val);
    }
The bug is still possible, as you've introduced an extra scope that doesn't exist in the C++ version.

Also, this was one example. There are plenty of other examples.


it's not that weird to explicitly limit the scope of certain variables that logically belong together.

But i agree the C++ if(init;cond) thing was new to me.


Like everything in C++, it has it's share of footguns

    if (Foo* f = GetPtr(); f->HasValue()) {} // wrong; f can be null
vs

    if (Foo* f = GetPtr(); f && f->HasValue()){}
Is probably the biggest pitfall. Especially if you're used to this:

    if (Foo* f = GetPtr())
    {
        f->DoTheThing(); // this is perfectly safe.
    }


Variables like "valueSet" scream out that the language lacks a Maybe type instead. One of the worst things about C++ is that it's content to basically not bother improving on the C type system.


C++ has optional, but I wanted to demonstrate that you could wrap a C API in a safer more ergonomic way.

If you rewrote it in a more modern way and changed the API

    std::optional<int> getFoo();

    if (auto val = getFoo()) {}
There are lots of improvements over C’s type system - std.array, span, view, hell even a _string_ class


I would vouch that C++ has plenty of improvements of C type system, even C++ARM already provided enough improvements that I never liked plain old C, other than that year spent learning C via Turbo C 2.0, before being given access to Turbo C++ 1.0 for MS-DOS in 1993.

The problem is all the folks that insist coding in C++ as if it was C, ignored all those C++ improvements over C.


C++ has a maybe type. It's called std::optional.


Here is my experimental maybe type for C: https://godbolt.org/z/YxnsY7Ted


Six divided by minus one is a "Division by zero" now? Where I come from that's minus six.

Good luck to WG14 (or maybe a faction within it?) as they seem to have decided to go make their own C++ competitor now, it's a weird time to do that, but everybody needs a hobby.


Yeah, I was about to add the test for INT_MIN / -1 but got distracted, but also not really the point of the example anyway.

I hope you realize that this is example does not need any complex C++ features.


I mean, sure. I read the "noplate" code. Did you ever watch the Mrs Merton show? "So, what first attracted you to the millionaire Paul Daniels?". There's a reason you felt the need to insist that your C language generic containers aren't relying on "complex C++ features" whatever you might decide that means.


The issue with C++ is that it is a hyper-complex language that really is a combination of four languages: C with classes, template code, macros, and constexpr code with largely overlapping functionality. It seems to be getting better in amalgamating these different parts, but it is still a mess that annoys me all the time when I try to use it. This complexity is what drove me away. Still there is a unmet need for generic programming in C and I can now do this with macros very well means I can have it without missing this part from C++. So the idea is not to reinvent C++ but to make minor tweaks to C to be able to do similar things in a much simpler way.


This will be in C2Y and is already supported by GCC 15: https://godbolt.org/z/szb5bovxq


This is one example. Off the top of my head std.array vs "naked" C arrays, string vs const char*, and let's not forget RAII are all features that just make me never want to work with vanilla C ever again.


For me, std.array seem fundamentally inferior compared to C arrays. A good standard string type is indeed missing, but it is also easy to define one. RAII, I can see, but I also some advantages to have explicit resource deallocation visible in the code and it is not really bothering me too much to write this explicitly.


C has less moving parts — it’s more difficult to define a subset of C++ that actually works across all platforms featuring a C++ compiler, not to mention of all the binary-incompatible versions of the C++ standard library that tend to exist — and C is supported on a wider variety of platforms. If you want to maximize portability, C is the way to go, and you run into much fewer problems.


Much easier to link / load into other language binaries surely.


extern “C” works just fine.


Only in certain limited cases, for example, can't have static class instances or anything else that could require calling before a call from "extern C" API.

Also now you have to build enough of a C API to expose the features, extra annoying when you want the API to be fast so it better not involve extra level of indirections through marshalling (hello, KDE SMOKE)

At some point you're either dealing with limited non-C++ API, or you might find yourself doing a lot of the work twice.


Only if your entire API doesn't contain any C++.


C is also C++, at least the C89 subset.



Do you usually post links without reading them?

"In the strict mathematical sense, C isn't a subset of C++. There are programs that are valid C but not valid C++ and even a few ways of writing code that has a different meaning in C and C++. However, C++ supports every programming technique supported by C. Every C program can be written in essentially the same way in C++ with the same run-time and space efficiency. It is not uncommon to be able to convert tens of thousands of lines of ANSI C to C-style C++ in a few hours. Thus, C++ is as much a superset of ANSI C as ANSI C is a superset of K&R C and much as ISO C++ is a superset of C++ as it existed in 1985.

Well written C tends to be legal C++ also. For example, every example in Kernighan & Ritchie: "The C Programming Language (2nd Edition)" is also a C++ program. "


> For example, every example in Kernighan & Ritchie: "The C Programming Language (2nd Edition)" is also a C++ program. "

That is rather dated, they do things like explicitly cast the void* pointer returned by malloc, but point out in the appendix that ANSI C dropped the cast requirement for pointer conversions involving void, C++ does not allow implicit void conversions to this day.


> Well written C tends to be legal C++ also

The "well written" remark is relevant.

Many style guides will consider implicit void conversions not well written C.

Naturally we are now on C23, and almost every C developer considers language extensions as being C, so whatever.


> The "well written" remark is relevant.

So using casts that hid implicit int declarations for years is "well written"?

> Many style guides will consider implicit void conversions not well written C.

I could not find a "Many" guide, Linux Kernel and ffmpeg seem to advocate against pointless casts.

> Naturally we are now on C23,

So irrelevant to the creation time of ffmpeg and only applicable to intentionally non portable libraries.


Well written idiomatic C is certainly not valid C++.


Depends on the beholder, however it hardly matters on the days of C23, as mentioned.


Do you usually post links without reading them?

all the time -- I call it "crowd-sourcing intelligence" :-)


I don't see your point. The thing you quote explicitly says C isn't a subset of C++.

> Well written C tends to be legal C++ also

and python2 can be written to be compatible with python3, but neither is a subset of the other


Unless I’m missing something, I don’t really see the point of putting the functions in the struct instance since it doesn’t seem like you need to use any form of polymorphism/function overriding.

If you have normal, non-virtual instance methods you are better off making it a normal function with some class centric naming pattern, e.g. JSON_Parse(JSON* self, const char* json).

If you want to emulate virtual functions from C++ you are better off storing a single pointer to a statically allocated vtable of function pointers (1 instance per class), that way your instance structs are smaller at the cost of an extra indirection per virtual call. You could also go the Rust route and use a large pointer type (pointer to object + pointer to vtable) for polymorphic objects that avoids a longer dependency chain at the cost of larger object pointers.


C compilers are still pretty bad at auto vectorization. For problems where SIMD is applicable, you can reasonably expect a 2x-16x speed up over the naive scalar implementation.


Also, if you write code with intrinsics the autovectorization can make it _worse_. eg a pattern is to write a SIMD main loop and then a scalar tail, but it can autovectorize that and mess it up.


Given the wider availability of masking (AVX-512, RISC-V and SVE), I figure scalar tails are no longer the preferred pattern everywhere.


It’s not a “gotcha” question, there’s clearly one right answer. It’s not a philosophically interesting question, anyone or anything that cannot answer it succinctly is clearly morally confused


If there’s clearly one right answer then why is it being asked? It’s so the questioner can either criticize you for being willing to misgender people, or for prioritizing words over lives, or for equivocating.


Point object could be either, since the coordinate systems are truly interchangeable, e.g. the class could just store everything as Cartesian internally and convert to/from polar as needed. In a class with more mutually exclusive properties I can see how this wouldn’t work so well.


Most of this sounds like the symptoms of an individualist society. If people only take into consideration their own incentives, why would they care about the experience of anyone else? In my opinion this world view is a result of a society that is only held together by the economic interests of individuals.


Technology isn’t the issue

Mass immigration and increasing wealth disparity are much more relevant.


Western elites have been pushing degrowth policies for the last decade or so. GP’s precise intent is unclear, but is probably suggesting there is a hidden, sinister purpose to it.


Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: