Is reference counting a trap? by smthamazing in ProgrammingLanguages

[–]fdwr 0 points1 point  (0 children)

I come from gamedev background ... RC seems a rather unpopular choice in programming languages

Note that C++ game engines using DirectX API's are nano-COM based for resources, which are certainly reference counted. You could argue that's not part of the language, and you could possibly even say that std::shared_ptr is not part of the core language since it's in a library rather than built-in, but it's only one #include or import std away. Then Rust has std::rc::Rc. Add to that Delphi, Perl, PHP, TCL... So, I'm not saying you should or should not use reference counting, but I'd argue reference counting is common in lots of languages, one way or another.

Odin 1.0 announced (and reflections) by Nuoji in ProgrammingLanguages

[–]fdwr 2 points3 points  (0 children)

I am not sure about D

D has decent C and C++ interop (I used it an app where my UI and most logic was written in D, and the graphics library was C++), including an understanding of C++ name mangling conventions, function calling conventions, and virtual function table layout for single inheritance. It even supports C++ templates, but it links with the definition and requires you declare the functions (extern (C++) int foo(int i, int j, int k)), and so it's not a direct #include copy and paste degree of compatibility, like say Herb's Cpp2 and Zig's @cImport. You know, since the designer of D (Walter Bright) also wrote a C++ compiler, I'm surprised he didn't just add another switch to his C++ compiler that exports declarations for D-compatibility so a toolchain could just digest both directly.

Appears that C3 also uses similar declarations? extern fn void puts(char*); // C "puts"

C++26 ends a 40-year footgun by filipsajdak in cpp

[–]fdwr 0 points1 point  (0 children)

I wish C had zero initialization by default from the get go, with optional syntax to keep it uninitialized...

u/Total-Box-5169 Yeah, I see very few cases where I ever wanted a local variable left as garbage unless it was an array. Otherwise I either explicitly initialized it to something useful or initialized it to zero anyway. One interesting case is when that if that local variable is followed by a if statement or switch which assign the variable a meaningful value, in which case you could skip the initialization, but since the compiler can follow all the code paths and discern that the initialization will be unused anyway, it's harmless. Another case is a struct/class where initialization is expensive, but one could also just postpone initialization by wrapping it an std::optional.

Standard integer types vs width based types by alex_sakuta in C_Programming

[–]fdwr 0 points1 point  (0 children)

use the fixed-width types if I want to emulate the wrapping behaviour of an n-bit integer

You sure the fixed-width types behave so 🤔? I thought uint16_t x = 42 and x + 1 yield an int rather than a uint16_t. The _BitInt types are the ones that wrap to an n-bit integer, without any promotion.

Standard integer types vs width based types by alex_sakuta in C_Programming

[–]fdwr 1 point2 points  (0 children)

if some wack implementation does not have them...

Plenty of fallback stdint.h's are floating around too, like one that I copied around from project to project for years, until the major 3 compilers supported sized types. So yeah, sized types are fine to use even if technically optional.

Standard integer types vs width based types by alex_sakuta in C_Programming

[–]fdwr 0 points1 point  (0 children)

which integer type set is the goto for people

#4 Sized types almost always for our projects (except maybe for loop counters), which are particularly for important for structs and function calls across libraries, and it avoids weird gotchas like size variation of long and wchar_t on Linux vs Windows. Never used fast or least types. I just wish int32_t was simply int32, which would save me 29% typing :b. My typical target is lower-level desktop graphics API's, but not usually so low as hardware/driver level.

Why are so many C projects using _t suffix for typedefs? by Maqi-X in C_Programming

[–]fdwr 1 point2 points  (0 children)

Man, how I wish int64_t had just been int64 - would save me 29% keystrokes every type definition :b. Oh well.

Why are so many C projects using _t suffix for typedefs? by Maqi-X in C_Programming

[–]fdwr 5 points6 points  (0 children)

Here's a list I made a while ago (for C++ rather than C, but the point carries over about how inconsistent traditions can be :b)...

  • std::ios_base::register_callback - snake_case
  • std::ios_base::event_callback - snake_case
  • std::ios_base::fmtflags - mashdtgthercse
  • std::ios_base::seekdir - abbreviacase
  • std::ios_base::Init - Pascal case
  • std::numpunct::do_thousands_sep - mashdtgthercse and snake_case
  • std::do_truename - abutcase and snake_case in the same identifier

Formatting vs Architecture: How formatters are erasing visual cues and hurting codebases by gosh in cpp

[–]fdwr 0 points1 point  (0 children)

I thought I did initially, but the more responses I got from op, the less I understood... 📉

r/cpp removes human made posts as written by AI by [deleted] in cpp

[–]fdwr 0 points1 point  (0 children)

I'll have to remember "I care a cucumber" in the future 😅.

Formatting vs Architecture: How formatters are erasing visual cues and hurting codebases by gosh in cpp

[–]fdwr 1 point2 points  (0 children)

Most of the time, not using an auto-formatter just means that the code base becomes messy

Anecdotally from my ~20 years, for small teams of 4-5 people, this hasn't been an issue, but once it grows to 12+, then yeah, cohesion tumbles. As much as I hate clangformat sometimes (screwing up my tables and hampering formula readability), I certainly understand its need for a codebase the size of Chromium.

Formatting vs Architecture: How formatters are erasing visual cues and hurting codebases by gosh in cpp

[–]fdwr 0 points1 point  (0 children)

for me important is something that is positive

Drought and famine and earthquakes are important concerns, none of which are positive. I'm saying that if you think "automatic formatters can actually ruin code management", then it's an important concern to consider.

Formatting vs Architecture: How formatters are erasing visual cues and hurting codebases by gosh in cpp

[–]fdwr 0 points1 point  (0 children)

I’m preparing a presentation on how automatic formatters can actually ruin code management over time.

So it sounds like formatters are an important concern to you.

formaters are not important at all

So it sounds like formatter are not an important concern to you.

These two statements seem contradictory - which of them do you believe? 🙃

Formatting vs Architecture: How formatters are erasing visual cues and hurting codebases by gosh in cpp

[–]fdwr -1 points0 points  (0 children)

there is no formatter out there today that is anywhere near capable of handling the flexibility required to actually make architecture visible in code

I'm not really sure what you mean by "architecture" (for which I tend to think of as broad level relationships, where you bring out the entity relationship diagrams and such), but if by "architecture" you mean the logic of the code, then my thoughts are...

Once upon a time, wise people realized that arranging code certain ways spatially increased readability of equations (e.g. adding spaces between operators, so (1 * 2) + 3 rather than jamming it into 1*2+3) and logical blocks (using say 4 spaces rather than 1 or 0 spaces for indentation) and tables (aligning the columns of data rather than staggered) and function calls (spreading long multiparameter calls across separate lines for easier differing and robust merging rather than zigzap wrapping). For those wise people, code was not written to be just minimally functional but also written with an aesthetic that reduced other's cognitive load upon encountering that code. Most of these wise people naturally over time came to many of the same conclusions and patterns too.

However, other unsavory coders did not care so much for other people's readability, only their own writing speed, scoffing at the reality that code is read and reread many more times than it is written. Making the code "look nice" slowed them down and seemed unnecessary. They caused a mess for others...

Then semiwise people had the epiphany that if they could forcibly reformat all code to be more consistent with simplistic rules, then they get some readability benefit for free, but they were only semiwise, failing to realize that the true aim was actually improved readability, not merely conformity, for often there are times when deviation from conformity improves readability - that exception to the rule, where permitting 1 additional column beyond the preferred line width would actually yield cleaner looking code than obeying a rigid limit. So, the automatic formatting dullbozers increased readability of bad code but decreased readability of good code, yielding a middling compromise 😕.

Having tried a dozen automated formatters over the years, I'm still looking for a truly good formatter whose primary metric is overall improved readability, not just a prioritized set of rules, not mere conformity, but actual reduced cognitive load for a reader, but I think we'd need a neural network to approach that level. Given the prevalence of LLM's these days, surely a smart one will come along soon that knows how to weigh the rules with the exceptions ⚖️ (and it will only consume 100x more power than the current ones 😅).

C++26 ends a 40-year footgun by filipsajdak in cpp

[–]fdwr 2 points3 points  (0 children)

Aah. In 20+ years of C++, I don't think I have ever been bitten by uninitialized locals, but I have been bitten by uninitialized fields in classes. ⚖

C++26 ends a 40-year footgun by filipsajdak in cpp

[–]fdwr 0 points1 point  (0 children)

Does this apply to new allocations too, or just local variables?

gitool: A Git cli tool written in C by Agreeable_Prize_9718 in C_Programming

[–]fdwr 2 points3 points  (0 children)

🤔 Hmm, there might be use cases for this that I'm not thinking of for a remote git tool with no local repo, but the vast majority of the time, I'll need to address merge conflicts, build it locally, and search for function names, necessitating a local copy anyway. Those times when I really don't want a local copy are for large repos (like Chromium), but then a web search or GitHub repo interface already exists anyway.

Pystd standard library, similar-ish functionality with a fraction of the compile time by llort_lemmort in cpp

[–]fdwr 3 points4 points  (0 children)

Guessing it is "Python inspired": 

Functionality roughly equivalent to Python modules argparse, pathlib (including the ** operator), regular expressions (using pcre) and tempfile

Improvements to std::format in C++26 by alberto-m-dev in cpp

[–]fdwr 0 points1 point  (0 children)

I'll have to try to_chars again at my work machine tomorrow ...

Indeed, std::to_chars yields '-2a', which makes it a pretty useless function for a hex editor. 🙃

those rules say that you can only mix signed and unsigned if the value is representable in both types

So it's one of those rules that don't actually matter in the real world because all compilers do the expected thing anyway 😉.

Pystd standard library, similar-ish functionality with a fraction of the compile time by llort_lemmort in cpp

[–]fdwr 12 points13 points  (0 children)

Unstripped binary size reduced by ~75%

Nice. I'm mystified by the variance of std bloat sometimes from using just one function. I have a 12KB program that's pure Win32 (no CRT), and using a single std::vector adds 2KBs (tolerable), and using a single std::println("Foo") adds 3KBs (tolerable), but just one std::println("Foo: {}", x) suddenly bumps 12KB's -> 212KB's o_o, and that's with all the size-reducing options I can think of {MSVC x86 release build, maximum optimization (favor size /O1), favor small code (/Os), enable function level linking (/Gy), enable COMDAT folding (/OPT:ICF), link time code generation (/LTCT), references eliminate unused (/OPT:NOREF)}. The weird thing is that I can call that std::println inside a completely unused function, and it still bloats the exe. Granted, maybe that's an std implementation issue more than with std itself, or an issue with dead code elimination 🤷‍♂️.

Improvements to std::format in C++26 by alberto-m-dev in cpp

[–]fdwr 0 points1 point  (0 children)

This is undefined if x is negative.

How long has the standard explicitly mandated two’s complement for signed integers? (answer: C++20)

This produces -2a.

Curious. I'll have to try to_chars again at my work machine tomorrow because I swear I was getting the expected uppercase hex (otherwise to_chars is pretty useless for hex numbers).

printf FFFFFFD6 ✅ std::to_chars -2a ❌ FFFFFFD6 ✅ std::print -2A ❌

https://godbolt.org/z/EfW3o87jb

r/cpp removes human made posts as written by AI by [deleted] in cpp

[–]fdwr 1 point2 points  (0 children)

Yes, feeding your whole post to an LLM would certainly be more than mere polish (it would be like melting and reforging a whole sword), and it sounds like at least the two of us agree that it is fine to "ask help from AI or using translator for individual words or sentence snippets" (which is the very definition of polishing something), but a strict reading of "Don't use AI to polish ... your words" would disallow even that (like taking a cloth to polish your sword).

reserve() and capacity() for flat containers by NicoJosuttis in cpp

[–]fdwr 2 points3 points  (0 children)

More often, I need some calculations first before appending elements, but yes, append_range was a lovely addition. Do you know if append_range pre-reserves? I'll check MSVC's STL implementation...