Live data from Hacker News

Initialization in C++ is Seriously Bonkers

mikelui.io

81–90 of 130 posts

Re: Initialization in C++ is Seriously Bonkers

#81
post #72

Earlier quoted context omitted.

Rust actually deliberately requires types to be declared, expect inside function bodies. So function return types have to be explicit. The main reason is exactly your readability argument. (Of course it also makes type inference inside the function body easier).

Yes, to be clear I wasn't accusing Rust code of having this particular problem, I was just using it as an example of a modern language where in my opinion there's a bit of an over-emphasis on brevity in terms of writing the code, as opposed to reading/understanding it and maintaining it, which I feel for long-term large projects, I'm not convinced is a total win. I could have easily used Go or Swift as examples inste…

I definitely agree with most of your points.

Code is read much more often than written, and most newer languages optimize for convenience rather than readability.

In my view Rust is actually pretty verbose compared to other new languages, and feels a bit cumbersome to write. Technically it could be made quite a bit leaner syntax-wise.

I just wanted to point out that Rust and the Rust community often share your view and want to optimize for readability as well. There actually was a lot of heated discussion last year around proposals that suggested reducing readability for convenience.

Re: Initialization in C++ is Seriously Bonkers

#82
post #38

Earlier quoted context omitted.

On oddball platforms it might be (though I think there's some quibbling as to whether the C runtime in such an environment is really distinct form "the OS"). It's not on Linux. The .bss segment becomes an anonymous mmap which is zeroed by the kernel when first accessed. Glibc never touches it. (Edit to correct: obviously glibc "touches" .bss because it has its own static variables. But there's no "zero .bss" step in…

./libgcc/config/nds32/crtzero.S .L_bss_init: ! clear BSS, this process can be 4 time faster if data is 4 byte aligned ! if so, use swi.p instead of sbi.p ! the related stuff are defined in linker script la $r0, _edata ! get the starting addr of bss la $r2, _end ! get ending addr of bss beq $r0, $r2, .L_call_main ! if no bss just do nothing movi $r1, 0 ! should be cleared to 0 .L_clear_bss: sbi.p $r1, [$r0], 1 ! Set 0…

How does finding some uncompiled sample code someone added to gcc for an architecture no one has heard of refute the point that glibc on Linux implements bss with an anonymous mmap?

Re: Initialization in C++ is Seriously Bonkers

#83
post #48

> C++ is not a language I’d want to teach beginners. At no point in this post was there room for systems programming concepts, discourse on programming paradigms, computational-oriented problem solving methodologies, or fundamental algorithms. This is a ridiculous argument. The entire point of the post was, as the author even noted, purely to deep dive into a rabbit hole, get super picky & pedantic about standards wo…

Hi. I appreciate your candor, although I'm not sure what I've done to inspire such contempt. You're correct that the entire point of the post was to deep dive into a rabbit hole. I acknowledged that and also acknowledged that the standardese is unnecessary most of the time, to avoid any miscommunication in my intent. I did this point out how large the language is and, more to the point, to point out how potentially c…

C might be okay to learn for academic purposes but it's an absolute nightmare to use building real things.

Things like strings and pointers are nightmarish in C. Segfaults aplenty.

I've never encountered a segmentation fault since switching to modern C++. Just because you use C++ doesn't mean you have to use the entirety of it.

Re: Initialization in C++ is Seriously Bonkers

#86
post #48

> C++ is not a language I’d want to teach beginners. At no point in this post was there room for systems programming concepts, discourse on programming paradigms, computational-oriented problem solving methodologies, or fundamental algorithms. This is a ridiculous argument. The entire point of the post was, as the author even noted, purely to deep dive into a rabbit hole, get super picky & pedantic about standards wo…

Hi. I appreciate your candor, although I'm not sure what I've done to inspire such contempt. You're correct that the entire point of the post was to deep dive into a rabbit hole. I acknowledged that and also acknowledged that the standardese is unnecessary most of the time, to avoid any miscommunication in my intent. I did this point out how large the language is and, more to the point, to point out how potentially c…

> how potentially complex it can be

Welp, time to go back to BASIC everyone. Or Go

Powerful tools can be complex, who would have thought

Re: Initialization in C++ is Seriously Bonkers

#87
post #5

In my view this author falls into the camp of people calling C++ a mess because it gives them too much control when they ask for it. One of his examples which he calls "The Abyss": #include struct A { A(std::initializer_list l) : i(2) {} A(int i = 1) : i(i) {} int i; }; int main() { A a1; A a2{}; A a3(3); A a4 = {5}; A a5{4, 3, 2}; std::cout which outputs: 1 1 3 2 2 he claims to be mysterious but is actually pretty r…

> it gives them too much control when they ask for it

Rust gives you too much control when you ask for it, with unsafe blocks, cells, etc. C++ will stab you in the gut at random because you looked at it the wrong way.

> But no other single language is good either.

I had Python for my CS101, Java for 102, C for 201, and C++ for ~202. This was a decade ago now, but even then I thought it was a pretty good track. You learn fundamentals of computation in Python fully apart from the hardware warts, you get to taste what the corporate monotony many of you will be faced with for decades to weed out the chafe, then you get a dose of cold hard reality when its too late to turn back that it gets even worse.

Re: Initialization in C++ is Seriously Bonkers

#89
post #17

Earlier quoted context omitted.

I think you're the fourth person jumping in to quibble with my "bss is zeroed by the OS" statement by snarking about "Ah hah! But what if you YOU ARE the OS?!". Yeah, I know. I live in that world too. I don't know that it's particularly relevant. The C standard is written to a norm of a Unix userspace environment, and that's clearly where the linked article is working.

It’s the C runtime that zeros it, not the OS. That’s my main point. The OS may initialize too, but that is outside the standard.

The OS does initialize it, so if you’re writing code for linux in any languages, or even in assembly, you won’t be able to spy on that retrieved memory.

Now C might want to do it too, but bare metal stuff is not necessarily compliant C so that doesn’t matter much.

Re: Initialization in C++ is Seriously Bonkers

#90
post #44

Author here--some extra context to add: The post was mostly written to point my students to, so I don't have to keep repeating myself. I get a not-insignificant number of 1st, 2nd, and 3rd years (in a 5-year program) believing C is some antiquated language and believing that they're getting held back in some way by learning C vs C++. One even suggested the department was incompetent for not teaching C++. Because I wo…

Why not teach rust?
Post reply on HN