News for hackers. Stuff that matters.
Re:The C23 edition of Modern C is now available for free by pjmlp on Tuesday October 15, 2024 @04:01PM (#41852524)
Perfectly iostreams happy user since 1993.
Re:The C23 edition of Modern C is now available for free by codr7 on Tuesday October 15, 2024 @04:44PM (#41852904)
Same, as long as I stay the hell away from locales/facets.

Type safe input/output stream types and memory backed streams served on a silver plate is a pretty decent improvement over C.

Re:The C23 edition of Modern C is now available for free by Dwedit on Tuesday October 15, 2024 @05:00PM (#41853058)
int a;

cin >> a;

Then the program goes berserk as soon as the first non-number is read out of standard input. All the other "cin >> integer" lines are immediately skipped.

Yes, I know about error checking, clearing error condition, discarding characters. But it's a whole lot of stuff you need to do after every single "cin>>" line. It makes the simplicity of cin not worth it.

Re:The C23 edition of Modern C is now available for free by eMSF on Tuesday October 15, 2024 @05:40PM (#41853403)
How could you ever continue after the second statement without checking if you actually read an integer or not? How would you know what you can do with a?
Re:The C23 edition of Modern C is now available for free by jvanderbot on Tuesday October 15, 2024 @07:57PM (#41854295)
You couldn't or wouldn't. but why have a read statement like cin>> which looks so nice and clean when you then have to go and check everything with flags and boolean casts on stateful objects.

I agree. It's lunacy. just be explicit and use functions or equivalent like literally every other language.

Re:The C23 edition of Modern C is now available for free by chongli on Wednesday October 16, 2024 @12:50AM (#41855723)
Well in a language like Haskell you could solve this with monads and do-notation. The general idiom in Haskell is to use a Maybe or Either monad to capture success/failure and you assume you’re on the happy path. Then you put the error handling at the consumer end of the pipeline when you unwrap the Maybe or Either.

I believe Rust has adopted similar idioms. I’ve heard the overall idea referred to as Railway-oriented programming.

In C++ you could implement it with exceptions, though they bring in a bunch of their own baggage that you don’t have to deal with when using monads.

Re:The C23 edition of Modern C is now available for free by tightbookkeeper on Tuesday October 15, 2024 @05:32PM (#41853339)
You’re holding it wrong. Like nan, the point is you don’t have to error check every operation.

You check error for the whole batch.

Re:The C23 edition of Modern C is now available for free by PaulDavisThe1st on Tuesday October 15, 2024 @11:46PM (#41855407)

   fscanf (STDIN, "%d", &a);
the program goes beserk as soon as the first non-number is read out of standard input.

in both cases, you need error checking (which you "know about").

Re:The C23 edition of Modern C is now available for free by unwind on Wednesday October 16, 2024 @03:54AM (#41856642)
No actual C programmer who has been around the block more than halfway should do that. The mantra is: "read into a character buffer, then parse that".

It's more code, sure, but it buys you a lot of good things. I/O is hard.

Re:The C23 edition of Modern C is now available for free by PaulDavisThe1st on Wednesday October 16, 2024 @09:37AM (#41858912)
No C++ programmer who has been around the block more than halfway should do

    cin >> a;
and assume that it works.

But also ...

    sscanf (the_buffer, "%d", &a);
doesn't help the problem in any substantive way.
Re:The C23 edition of Modern C is now available for free by tightbookkeeper on Tuesday October 15, 2024 @05:33PM (#41853344)
Yep, it’s very clean once you get the hang of it.
Re:The C23 edition of Modern C is now available for free by einpoklum on Tuesday October 15, 2024 @05:43PM (#41853427)
Then I suppose you don't care about:

* Performance

* Support for localization (as the format string and positions of values to format differ between languages).

* Code reuse & dogfooding - the data structures used in iostreams are not used elsewhere, and vice-versa

* C and OS interoperability - as you can't wrap a stream around a FILE* / file descritor

* bunch of other stuff...

iostreams work, but are rather crappy.

Re:The C23 edition of Modern C is now available for free by pjmlp on Tuesday October 15, 2024 @06:05PM (#41853587)
I care about performance, when it actually matters to acceptance testing.

The less C the merrier.

If you care about correct use of localisation, standard C and C++ libraries aren't really what you're looking for, or even C and C++ to start with.

Re:The C23 edition of Modern C is now available for free by wakawaka28 on Tuesday October 15, 2024 @07:47PM (#41854253)
C and C++ are the bedrock of operating systems with the best performance and extensive support for all languages.

The only reason why iostreams are slow is because of its incompatible buffering scheme, and the fact that C and C++ need to stay in sync when linked together. And that brand of slow is still faster than other languages, except sometimes those that delegate i/o to pure C implementations.

Re:The C23 edition of Modern C is now available for free by pjmlp on Wednesday October 16, 2024 @03:22AM (#41856448)
Historical baggage, they weren't the first system programming languages, got lucky with UNIX's license allowing for widespread adoption, and won't be the last one standing either.
Re:The C23 edition of Modern C is now available for free by wakawaka28 on Wednesday October 16, 2024 @02:35PM (#41862240)
Considering that they are evolving, I think they are more likely than not to stay standing. There might be other similar languages developed in parallel, but after over 30 years of whining C and C++ are still popular. I don't expect that to change.
Re:The C23 edition of Modern C is now available for free by throwaway2037 on Tuesday October 15, 2024 @10:53PM (#41855144)

    > If you care about correct use of localisation, standard C and C++ libraries aren't really what you're looking for, or even C and C++ to start with.
What do you recommend instead?
Re:The C23 edition of Modern C is now available for free by PaulDavisThe1st on Tuesday October 15, 2024 @11:47PM (#41855414)
_("some text") ... aka gettext and friends.
Re:The C23 edition of Modern C is now available for free by maccard on Wednesday October 16, 2024 @04:20AM (#41856784)
QT, unfortunately.
Re:The C23 edition of Modern C is now available for free by throwaway2037 on Wednesday October 16, 2024 @04:34AM (#41856862)
Why do you "unfortunately"?
Re:The C23 edition of Modern C is now available for free by maccard on Wednesday October 16, 2024 @08:31AM (#41858325)
It's like using a sledgehammer for a picture hook. I think QT is a great tool, and it solves this problem nicely, but it's a full blown framework, and if you're already using something else - particularly if it's something "light" like SDL, or just a platform specific library like Win32, it's an awful lot to pull in (plus compile times, licensing, etc).
Re:The C23 edition of Modern C is now available for free by throwaway2037 on Friday October 18, 2024 @10:16AM (#41879701)
If you are using SDL, what is wrong with GNU gettext()?
Re:The C23 edition of Modern C is now available for free by fra on Tuesday October 15, 2024 @09:05PM (#41854676)
This was a tip my hatn excellent to you
Re:The C23 edition of Modern C is now available for free by johnisgood on Tuesday October 15, 2024 @10:04PM (#41854939)
Why?