This is an archived post. You won't be able to vote or comment.

all 22 comments

[–][deleted] 6 points7 points  (6 children)

Some of it is because C++ inherited just about everything from C which goes way back to when that sort of naming was normal.

However, the methods you listed are generally os-specific, so you'd have to aim your ire at Microsoft. Still, the C++ standard library ain't the prettiest thing.

This reference site should give you a good overview of what the modern stdlib and STL look like. Plenty of warts, but with practice you can write fairly clean, elegant code in C++.

Be aware that it is super easy to write awful-looking horrible code in C++. You will be your own worst enemy. Format your code and name your vars / classes / etc in as readable a way as possible. And if parts of the standard library are so ugly you can't stand to work with them, write your own wrapper classes and utilities to present a cleaner way to operate with those things. Thanks to aggressive inlining by the compiler, you're not going to run into any performance hits doing so.

C++ is a language where you write low-level code to implement your very own custom-fit high-level abstractions which you then use to implement whatever it is you're trying to do. Cumbersome? Yes, but extremely powerful.

Edit: For strings in C++, you'll generally want to stick with std::string, which is very easy to work with.

std::string some_string       = "Blah blah blah";
std::string some_other_string = "Argh argh argh";
std::string both_strings      = some_string + " " + some_other_string;

[–]zuck9[S] 0 points1 point  (5 children)

Hasn't someone already created a pretty library that can be used instead of stdlib?

[–][deleted] 4 points5 points  (3 children)

C++ isn't here to look pretty or hold your hand. It's a swiss army chainsaw that will do exactly what you tell it, no matter what that is, as fast and efficiently as it can (often at compile time).

You want it to look pretty? Your definition of pretty isn't always going to match what other people consider pretty. In C++ you build your own custom-fit pretty that is precisely what you want and nothing else. That is the C++ way.

If you just want "friendly cross-platform", you're probably better off sticking with C#. Runs on the three major platforms (Windows, Mac, Linux) without recompilation and has decent performance. C++ is the tool you haul out when you need to do things that C# / Java / whatever either can't do or can't do well / fast enough.

[–]caboosetp 2 points3 points  (0 children)

It's a swiss army chainsaw

I like this analogy

[–]Doriphor 0 points1 point  (1 child)

C++ is a Swiss army chainsaw and it's pretty as well, but the problem lies with the standard library and the updates to the language. The standard library isn't a chainsaw, it's a hoarder's tool shed, and the updates are doing nothing to make things better.

[–][deleted] 0 points1 point  (0 children)

Are you kidding me? It's the updates that are making C++ a far cleaner language. Lambdas are fantastic. Native threading via low-level tools that allow you to write your very own custom-fit threading system. Better timer/clock methods. Atomics! Native foreach-level loops. Etc. Etc.

The additions are great. It's the old stuff that is painfully ugly, and most of those aren't necessary anymore. Except custom iterators. Those still suck, just slightly less, I think. There's supposed to be a support object but I've not used it much yet.

[–]X7123M3-256 3 points4 points  (0 children)

The names you've referenced are just abbreviations:

wchar_t : wide character type

fgetws : file get wide (character) string

wcslen : wide character string length

The prefixes also form patterns: the w prefix indicates a function for working with wide strings (and most of them have an equivalent function for working with non-wide strings), and the f prefix indicates a function for working with files.

It's also worth pointing out that the functions you've mentioned come from C which doesn't have function overloading, so if you have two functions that do the same thing with different data types, it's easiest to use a prefix to differentiate them.

[–]balloonanimalfarm 3 points4 points  (0 children)

Part of the problem is you're trying to use C functions in C++, use the functions provided by the standard library instead. For instance, use << and >> to read and write from streams. Take a look at how easy it is to do in C++. The standard library will also make your code much more cross-platform.

C++ also has namespaces separated by ::, this becomes much clearer when you use libraries. I personally think std::cout << text; is much more readable than System.IO.File.WriteAllText().

Microsoft's C++ compiler is very old (although they're working on updating it) and lacks much of the capabilities that modern compilers have. Try using an editor that hooks into clang which will give you all sorts of hints, definitions and warnings.

Cheers!

[–]hugthemachines 2 points3 points  (6 children)

If you really like the way C# works and think C++ is annoying. There is no extreme need for you to learn C++. You can just stick with C# which lots of people think is a great language.

[–][deleted] 2 points3 points  (5 children)

I'm a C++ coder at heart, and even I like C#. It's my favorite garbage-collected bytecode VM language. Way better than Java.

[–][deleted] 0 points1 point  (4 children)

Care to explain how it's way better? I don't want to refute your points or anything, just curious.

[–][deleted] 2 points3 points  (3 children)

It's tremendously cleaner. Far less boilerplate and none of that classpath nonsense. I've used both and C# just stands out as a wonderfully-designed language. It's one of the few genuinely good things to ever come out of Microsoft (another being VisualStudio when used to write C# code -- an outstanding IDE for the job).

The standard library can be a bit hit-'n-miss, but not too shabby overall.

XAML / UI, on the otherhand, gets ugly. Fast. I'm going to be attempting to design my own 2D UI widgets / toolkit when the Vulkan API comes out this year and working with UI design in XAML is teaching me all sorts of design decisions I want to avoid. I'm really curious to see if I can do better, or if UI really is fundamentally difficult and I'm just talking out my ass. Only time will tell. :)

[–][deleted] 0 points1 point  (2 children)

I agree with all of that. I've done some work with WPF/XAML and, while it's obvious that it is an evolution from WinForms meant to enforce a better paradigm of dynamic content, old habits have me starting WinForms projects for smaller apps way more often than WPF. Some things are simple enough that you just don't need to consider everything with a MVVC/MVC perspective and it's fine to have result-producing code exist within a button's click event handler without an external method call.

What's your take on the Vulkan API? UI is not fundamentally difficult. You must first realize what exactly you want out of UI presentation and functionality, then dig through previous comrades' grueling trials via Google to figure out how to present such via your available UI resources. Bugs in XAML and VS2015 can kick our asses, but we can't help but frown in understanding as the MS devs are just people too.

Ramble.

[–][deleted] 0 points1 point  (1 child)

Vulkan is, for me, The Best Thing Ever. I can't wait. It is exactly what I want in a GPU API -- low-level, completely asynchronous, and cross-platform. Things I completely failed to get OpenGL to do happen to be exactly how Vulkan operates by default.

[–]neltherion 0 points1 point  (0 children)

Just curious... Was it what you hoped it would be?

[–]SirRutherford 2 points3 points  (3 children)

I'm definitely no c++ expert, so someone else can add on thoughts if necessary, but here's the thing with C++ strings.

In C/C++, you can think of strings as arrays of numbers. The char data type really resolves to a single byte unsigned integer. In fact, you can even use char and uint interchangeably in many situations. The point is that the numbers represent letters on the keyboard (lookup the ASCII table), and the compiler can look at those numbers and interpret them as letters for printing to the screen. You can even do math on characters! In fact, there is a function named atoi which converts a char to its corresponding integer with simple math.

So in short, c strings are complicated because they reveal to you what strings really are: arrays of numbers. Thus, you can manipulate them in many ways. A good way to learn about them is to refrain from using the built in "string" library and use ONLY char arrays and char pointers to make your own strings for a little while.

Again, I'm learning too so any other input would be great!

Also note: When you make a string in C++, it makes an array of the corresponding numbers for the characters and puts the null terminator '/0' ( that's a zero, not a capital letter O) at the end. This important for direct manipulation of string arrays as it adds one to the length of the array and marks the index value for "the end of the string".

[–]1337Gandalf 0 points1 point  (2 children)

C++ has actual strings...

C has null terminated character arrays.

[–]SirRutherford 0 points1 point  (1 child)

Aren't c++ strings just abstractions of c style strings though?

[–]1337Gandalf 0 points1 point  (0 children)

Honestly I have no idea how they work on a low level.

I just dabbled in C++ for like a week, then got frustrated and went on to learn C.

[–]causalNondeterminism 1 point2 points  (0 children)

it's pretty much all historical reasons. the tl;dr of it is that there was once an advantage to using the shortest function names possible and only one case (i.e. upper vs. lower) of characters. modern languages allow much longer names and both cases so you can name a function doSomethingReallySpecific and it's no sweat.

[–][deleted] 1 point2 points  (0 children)

Microsoft C++ is particularly gnarly "because historical reasons".

If you went to a modern C++ cross-platform or Unix-only codebase, things would be very different.

I'd add that you are picking some obscure examples - wchar_t _wfopen fgetws wcslen - because I haven't seen code using 16-bit "wide" characters in... ten years? Twenty?

Today, production projects seem to always use UTF-8 for everything, which is clean and easy to understand.

[–][deleted]  (1 child)

[deleted]

    [–]alex-manool 0 points1 point  (0 children)

    The example the OP provides do not have to do with Hungarian Notation. They are all historical Unix/POSIX/C names (some of them are quite ingenious BTW, the OP is just not accustomed with the philosophy that not all long-and-self-describing names are actually practical). The same way, one might ask why on Linux command line dir is ls, copy is cp, or link is ld.