Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Slurps Mad Rips
Jan 25, 2009

Bwaltow!

There are many things wrong with iostreams. God objects, virtual inheritance, the lack of a replacement for strstream which has been deprecated since 1998, they're only really ever used for text because holy gently caress could you imagine having to worry about supporting both text and binary in your operator << (let alone endianness)? Gimme ADL and some concrete types that don't allocate 492 bytes on the stack on a 64-bit system everytime I want to open a file just so I can do whatever. I'll be over here with this posix file descriptor wrapper that uses a std::vector<uint8_t> for buffering and readv/writev for filling said buffer.

They do make it pretty easy to parse CSV files, though so I guess that's a bonus.

Adbot
ADBOT LOVES YOU

sarehu
Apr 20, 2007

(call/cc call/cc)
printf is pretty much fine, but for some reason Visual Studio, or its compiler, can't see through macros when warning about incorrect format strings.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

SAHChandler posted:

There are many things wrong with iostreams. God objects, virtual inheritance, the lack of a replacement for strstream which has been deprecated since 1998, they're only really ever used for text because holy gently caress could you imagine having to worry about supporting both text and binary in your operator << (let alone endianness)? Gimme ADL and some concrete types that don't allocate 492 bytes on the stack on a 64-bit system everytime I want to open a file just so I can do whatever. I'll be over here with this posix file descriptor wrapper that uses a std::vector<uint8_t> for buffering and readv/writev for filling said buffer.

They do make it pretty easy to parse CSV files, though so I guess that's a bonus.

you forgot about how the objects are stateful and are modified by passing magic other objects to the streams as an output operator

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Suspicious Dish posted:

you forgot about how the objects are stateful and are modified by passing magic other objects to the streams as an output operator

honestly, that's the best part right there. I wish I'd been there to overhear what approaches they rejected in favour of that one.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Suspicious Dish posted:

you forgot about how the objects are stateful and are modified by passing magic other objects to the streams as an output operator

when i learned this my reaction was a lot like seinfeld.gif

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
i love that i can gently caress up somebody else's program by doing cout << hex;

such a cool feature

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

Suspicious Dish posted:

you forgot about how the objects are stateful and are modified by passing magic other objects to the streams as an output operator

Ugh, yes. Huge pain in the rear end, and the boost iostream state poo poo can only do so much...

Subjunctive posted:

honestly, that's the best part right there. I wish I'd been there to overhear what approaches they rejected in favour of that one.

I am actually working on a replacement for streams that might be more amenable (and is also backwards compatible), but have had little time to focus on it as of late. It isn't directly related to my job, and the few people I've shown it to showed interest. But, I'm a small unknown engineer in a sea of literally thousands at my employer and even my manager doesn't know how to approach our committee representatives or what we would need to do to get feedback before going public with the proposal and sample implementation.

Also, it's a fairly ambitious thing to replace streams, but at a minimum this would just give folks a way to declare a binary i/o and text i/o approach. One nice thing that my approach does is allow for custom allocators like the rest of the stdlib, so you don't end up in these weird situations where you call new on an object and hope for the best, like imbuing a facet (seriously gently caress facets). Also, exceptions as error reporting are optional for each 'resource' that you write to so there could be a file resource that uses std::error_condition for error reporting instead of some cronenberg mix of setting various bits to represent errors and then throwing your hands up in the air and using FILE*

Also, no operator overloading.

gently caress streams.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
wait a minute... holy poo poo

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
"hm, something about replacing streams, that sounds like SAHChand-"

HOLY poo poo

so, we still touching butts this week at zeitgeist?

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

Suspicious Dish posted:

"hm, something about replacing streams, that sounds like SAHChand-"

HOLY poo poo

so, we still touching butts this week at zeitgeist?

Hell yeah.

Bloody
Mar 3, 2013

lol more like sahc handler

Notorious b.s.d.
Jan 25, 2003

by Reene

sarehu posted:

printf is pretty much fine, but for some reason Visual Studio, or its compiler, can't see through macros when warning about incorrect format strings.

"the language is fine, but for some reason my IDE fails to statically analyze a turing complete macro system before parsing a special dsl that exists outside the type system"

Sapozhnik
Jan 2, 2005

Nap Ghost
c++ stdlib was written by one grad student and is full of failed experiments and useless poo poo as well as omitting all sorts of actually useful things (such as idk sockets i hear there's this new internet thing that's popular with kids these days)

i mean it's loving amazingly good for being grad student code but that ain't saying much

the more irritating thing aspect of it is that :byodood: std::string and std::vector were designed by people much smarter than you, don't ever roll your own!! we could quite easily ignore it otherwise

there's no mandatory java.lang.Exception type thing in c++ either but there might as well be: std::exception is magical because std::bad_cast derives from it and std::bad_cast IS magical, it's thrown by dynamic_cast<>. at least it returns a const char * as opposed to a std::string thereby making std::string magical too.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Mr Dog posted:

the more irritating thing aspect of it is that :byodood: std::string and std::vector were designed by people much smarter than you, don't ever roll your own!! we could quite easily ignore it otherwise

as long as you use them in the intended* way, i.e. as bounds-checked, resizable, type-safe replacements for C strings and C arrays, they're alright. as actual containers they suck donkey balls because (among other things) they are value types and copying a 1 GB std::vector gives you another, distinct 1 GB std::vector, where you'd expect them to be references to shared copy-on-write storage like they'd be in any other language. which wouldn't be so bad if there were, in fact, standardized storage-sharing containers. I guess just pass shared_ptrs around everywhere :effort:

*not stated anywhere in documentation ofc

a cyberpunk goose
May 21, 2007

hi SAHChandler

MononcQc
May 29, 2007

E: wrong thread

MononcQc fucked around with this message at 18:21 on Mar 11, 2015

Sapozhnik
Jan 2, 2005

Nap Ghost

hackbunny posted:

as long as you use them in the intended* way, i.e. as bounds-checked, resizable, type-safe replacements for C strings and C arrays, they're alright. as actual containers they suck donkey balls because (among other things) they are value types and copying a 1 GB std::vector gives you another, distinct 1 GB std::vector, where you'd expect them to be references to shared copy-on-write storage like they'd be in any other language. which wouldn't be so bad if there were, in fact, standardized storage-sharing containers. I guess just pass shared_ptrs around everywhere :effort:

*not stated anywhere in documentation ofc

that's not even the problem. reference counting and copy-on-write poo poo are expensive and should definitely be an opt-in thing. if you don't want to care about that then go program in Java (which is basically what i did in the end btw and never looked back, gently caress having to micromanage that poo poo in the 99% of cases where it really doesn't matter).

the problem is crap like std::allocator<> that absolutely nobody uses, or microsoft's loving influence leading us to have std::string and std::wstring and both suck donkey balls at dealing with utf-8 like everybody else on the loving planet (basically you'd have to write your own UTF-8 codec to translate between byte streams and std::wstream objects). std::string provides no type safe printf-like thing. yes there are issues with it as described above but it's better than the iostreams abomination we do get.

also the general opinion these days is that you should have both mutable and immutable containers, for example: immutable strings and mutable stringbuffers. std::string is mutable which is bad.

JawnV6
Jul 4, 2004

So hot ...

Suspicious Dish posted:

so, we still touching butts this week at zeitgeist?

what now

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

Mido posted:

hi SAHChandler

hi

Mr Dog posted:

the problem is crap like std::allocator<> that absolutely nobody uses, or microsoft's loving influence leading us to have std::string and std::wstring and both suck donkey balls at dealing with utf-8 like everybody else on the loving planet (basically you'd have to write your own UTF-8 codec to translate between byte streams and std::wstream objects). std::string provides no type safe printf-like thing. yes there are issues with it as described above but it's better than the iostreams abomination we do get.

also the general opinion these days is that you should have both mutable and immutable containers, for example: immutable strings and mutable stringbuffers. std::string is mutable which is bad.

the string_view implementation apparently got enough requests to permit mutating the underlying string instead of just acting as a mutable view over immutable chars so now we're going to have a const string_view and a non-const form and this makes me sad :(

you can use <codecvt> to convert between utf-8 and utf-16 and vice versa. It's as easy as

1)
code:
#include <utility>
#include <codecvt>
#include <locale>
#include <string>
2)
code:
std::string data = u8"\u00df\u6c34\U0001f34c";
3)
code:
template <class Facet>
struct deletable_facet : Facet {
  template <class... Args>
  deletable_facet (Args&&... args) : Facet(std::forward<Args>(args)...) { }
  ~deletable_facet () = default;
};

std::wstring_convert<deletable_facet<std::codecvt<char16_t, char, std::mbstate_t>>, char16_t> conv16;
std::u16string str16 = conv16.from_bytes(data);
(lmao, facets are a nightmare, but you can do something like the above to do a conversion or something? the whole thing is a nightmare)

Soricidus
Oct 21, 2010
freedom-hating statist shill

Notorious b.s.d. posted:

"the language is fine, but for some reason my IDE fails to statically analyze a turing complete macro system before parsing a special dsl that exists outside the type system"

cpp macros aren't turing complete, although boost sure wishes they were

Notorious b.s.d.
Jan 25, 2003

by Reene

Soricidus posted:

cpp macros aren't turing complete, although boost sure wishes they were

i am certain the c++ preprocessor is, because people have demonstrated it using templates

i think the regular cpp is, also. there's a plausible example on stackoverflow:
http://stackoverflow.com/a/10526117

in any case, statically analyzing code that edits itself with arbitrary depth text substitution is not real pleasant

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Notorious b.s.d. posted:

i think the regular cpp is, also. there's a plausible example on stackoverflow:
http://stackoverflow.com/a/10526117
i dont thin this counts. it looks primitve recursive at best?

quote:

in any case, statically analyzing code that edits itself with arbitrary depth text substitution is not real pleasant
still true

Soricidus
Oct 21, 2010
freedom-hating statist shill

Notorious b.s.d. posted:

i am certain the c++ preprocessor is, because people have demonstrated it using templates

i think the regular cpp is, also. there's a plausible example on stackoverflow:
http://stackoverflow.com/a/10526117

in any case, statically analyzing code that edits itself with arbitrary depth text substitution is not real pleasant

templates are irrelevant to this discussion. they are a completely separate thing from macros and have nothing to do with the preprocessor.

regular cpp can be abused like that, but generally is not. the only common usage of cpp that abuses it like that is boost. and if you're the kind of person who uses boost, you've probably bought into c++ enough that you're not touching cstdio in any case. so that, too, is irrelevant. printf wrappers of the sort that sarehu was actually complaining about will tend to be trivial substitutions.

ultimately my point is that there's no good reason for the ide not to handle the simple, common cases. i mean, if you're going to give up just because there are unpleasant edge cases, why are you even trying to do static analysis in the first place? you're always going to encounter unpleasant edge cases. but that doesn't matter in reality because ignoring unpleasant edge cases still lets you do really useful analysis.

Notorious b.s.d.
Jan 25, 2003

by Reene
maybe we could design programming languages that don't require our tools to do backwards handsprings with heuristics to check trivial errors

sarehu
Apr 20, 2007

(call/cc call/cc)

Notorious b.s.d. posted:

"the language is fine, but for some reason my IDE fails to statically analyze a turing complete macro system before parsing a special dsl that exists outside the type system"

Actually I don't use VS, it's cl the compiler that fails to do this. You'd think it would be able to just expand the macro and check the function call, but nooooooo. gcc does it just fine.

JawnV6
Jul 4, 2004

So hot ...

Notorious b.s.d. posted:

maybe we could design programming languages that don't require our tools to do backwards handsprings with heuristics to check trivial errors

LOLR

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Notorious b.s.d. posted:

maybe we could design programming languages that don't require our tools to do backwards handsprings with heuristics to check trivial errors

when was the last time you got burned by a printf type error? how much time did it take to track down and fix?

Notorious b.s.d.
Jan 25, 2003

by Reene

HappyHippo posted:

when was the last time you got burned by a printf type error? how much time did it take to track down and fix?

lol

just lol

Notorious b.s.d.
Jan 25, 2003

by Reene
i don't even need working type checking, printf errors never happen and my time is valueless so i don't mind hunting for them :smug:

Notorious b.s.d.
Jan 25, 2003

by Reene
happyhipo i bet you would enjoy writing php for a living

sarehu
Apr 20, 2007

(call/cc call/cc)
Well printf is typechecked. It's a known deficiency that has been fixed.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Notorious b.s.d. posted:

i don't even need working type checking, printf errors never happen and my time is valueless so i don't mind hunting for them :smug:

says the guy who posts here 800 times a day

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

sarehu posted:

Well printf is typechecked. It's a known deficiency that has been fixed.

no but you see it isn't in the language specification so that is hurting me because ????

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Mr Dog posted:

that's not even the problem. reference counting and copy-on-write poo poo are expensive and should definitely be an opt-in thing.

as I mentioned before I'm now finally using C++ for a product, and I don't know what I'd do without Qt's copy-on-write QList, QMap, QString etc. you need to pass that poo poo around all the time, especially strings. especially strings! vectors, ok, but how the hell can you not have reference-counted immutable strings in tyool 2015? all frameworks I've ever used have them - even winrt has them!

I must be getting old because my priorities are shifting. I now give zero fucks about things like ensuring that copying a container of N elements predictably results in calling N element copy constructors, as no doubt has been pedantically specified somewhere. I want useful things in my languages, as in things I can use in the code I write for a living

Mr Dog posted:

the problem is crap like std::allocator<> that absolutely nobody uses

I tried once or twice and it's an incredibly weird interface for an allocator. it doesn't fit right as a wrapper over a malloc-like API, nor as an object pool

Mr Dog posted:

also the general opinion these days is that you should have both mutable and immutable containers, for example: immutable strings and mutable stringbuffers. std::string is mutable which is bad.

mutable vs immutable is done really well in Objective C and with very low overhead

and if you want to do immutable right, you will have to use shared storage anyway, otherwise why not just use a const object

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Laugh Or Load Register

https://twitter.com/ppcinstructions

Notorious b.s.d.
Jan 25, 2003

by Reene

sarehu posted:

Well printf is typechecked. It's a known deficiency that has been fixed.

Dessert Rose posted:

no but you see it isn't in the language specification so that is hurting me because ????

guys, we put a bandaid on this gunshot wound

i think we can call this a job well done

Notorious b.s.d.
Jan 25, 2003

by Reene
writing poo poo to parse specifically printf's lovely dsl, analyze the arguments, and issue warnings about it is dumb. it fixes one symptom but it doesn't address the cause

what if the user wants to define his own function?
or worse, a printf wrapper?

it's a hack layered on hacks. hacks all the way down

sarehu
Apr 20, 2007

(call/cc call/cc)
I actually worked on a project that used that allocator type parameter everywhere. It was a mistake and everything was better when they switched to tcmalloc and then later jemalloc.

quote:

what if the user wants to define his own function?
or worse, a printf wrapper?

They thought of this and solved that problem, did you know?

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

sarehu posted:

They thought of this and solved that problem, did you know?

of course he doesn't, he doesn't actually care, he's just randomly firing shots in all directions hoping to hit something

news alert, at some point your code has to get things done, and sometimes that means you have to implement something in a way that isn't the cleanest possible

Adbot
ADBOT LOVES YOU

b0lt
Apr 29, 2005

Notorious b.s.d. posted:

writing poo poo to parse specifically printf's lovely dsl, analyze the arguments, and issue warnings about it is dumb. it fixes one symptom but it doesn't address the cause

what if the user wants to define his own function?
or worse, a printf wrapper?

it's a hack layered on hacks. hacks all the way down

__attribute__(((((((((((((((format(printf,1,2))
i wonder why they numbered from 1 for this

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply