[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Why is C++ so ugly?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 102
Thread images: 12

File: disgustingAngleBrackets.png (15KB, 640x400px) Image search: [Google]
disgustingAngleBrackets.png
15KB, 640x400px
Why is C++ so ugly?
>>
>>58708038
Why is your post so ugly?
>>
>>58708038
That's not even valid C++
>>
File: snake.png (11KB, 422x60px) Image search: [Google]
snake.png
11KB, 422x60px
I always lol at how much less code python takes to do the same thing.

Yet at the same time marvel at how much more powerful C++ is.
>>
>>58708038

Why is C not type safe?
>>
>>58708114
Because types is a high-level concept and C is intended to merely be a portable assembly.
>>
>>58708051
Post is beautiful anon

>>58708071
But is it anon. Just no endl
>>
>>58708140
>iostream.h
>.h

>no return type for int

>cout is on default namespace instead of std

It's not valid C++
>>
>>58708167
You may be right, but that doesn't invalidate my point that C++ output is ugly with its angle brackets.
>>
>>58708227
>angle brackets
C also has "angle" brackets, anon, it's the logical shift operator.

#include <stdio.h>
int main()
{
printf("%x\n", 1 << 3);
return 0;
}


Anyway, if you don't like C++'s concept of output streams, just use stdio

#include <cstdio> // <--

int main()
{
puts("This is valid C++");
return 0;
}
>>
>>58708113

> a script language for children is simple

paint me surprised
>>
>>58708133

This. C is a meme language beyond extreme low level. Go C# and WPF for anything high level and serious.
>>
>>58708113
>python = less code
std::cerr << "text\n";


print >> sys.stderr, "text"
>>
>>58708333
simplicity and ease-of-use is why python is a great scripting language
>>
>>58708377

You are a faggot for not running Visual Basic then.
>>
>>58708388
>Visual Basic
>simplicity and ease-of-use
Pick one
>>
>>58708038
i unironically think c++ is beautiful
>>
>>58708273
I don't write much C++ but took a c++ class in college. That bitch never never showed us cstdio. Wrote so much
cout << "bla bla bla" << endl;

I wanted to kill my self.
>>
>>58708476
Well, until the gazilleon different C++11 std::to_string, output streams and output stream buffers were objectively easier to deal with. But now, I just do

std::string text = "this is a number: ";
text += std::to_string(2);
printf("%s\n", text.c_str());
>>
>>58708405

Nigga it's so painfully simple and easy that I literally stopped using it in favor of C# for that reason.

Granted, C# has more support in forums but still, it was so easy I couldn't bear it.

Granted, I have experience from C to assembler so I'm not new, but still.
>>
>>58708539
I used to program Visual Basic. I honestly and sincerely think that C++ is easier than having to deal with all of the Microsoftianisms that come with that shit and that you can't opt out of. I guess .NET is somewhat similar in that aspect.
>>
File: hw.png (10KB, 332x98px) Image search: [Google]
hw.png
10KB, 332x98px
>>58708038
Swift is godly
>>
Python requires aligning statements depending of loop types. It's a regression to the 60's when it was required by languages such as COBOL and FORTRAN.
>>
>>58708782
The one thing i don't like about python is its use of white space. I'm to use to brackets.
>>
>>58708038
Why do you shitpost if you can't write the most basic C++ code correctly?
>>
>>58708038
> implying stdio.h is absent in c++ standard library
>>
>>58708909
to get you to reply
>>
>>58708476
There are a million ways to do things in C++.

That's part of why people are weary about the language.
>>
File: More than godly.png (630B, 136x38px) Image search: [Google]
More than godly.png
630B, 136x38px
>>58708634
Then what is K?
>>
>implicitly typed main
>main declared with unspecified parameters
>random white spaces after printf
>not appending a newline at the end of printf

You're a shit c programmer


>declaring main without a type in C++, which is illegal
>returning 0 instead of EXIT_SUCCESS

You're also a shit C++ programmer. You can also use printf in C++.
>>
>>58708038
Your example only shows what it is like to print a single string.

Say you want to print a string and a number, printf can do that.
But you have to specify if it is an int, unsigned int, or a double.
You cannot print objects, you cannot redirect the stream to something else, say a log or a file.

Stuff like that is very useful to most programmers.
You can effortlessly print stuff, turn stuff into a string and then print it.
Obviously you could solve this in a different way, but cout works really well.
>>
File: 1475100110792.jpg (58KB, 650x650px) Image search: [Google]
1475100110792.jpg
58KB, 650x650px
>>58708113
You practically compared apples and oranges just then.

I recommend you read into the differences between C and Python before you continue to speak uninformed in future.
>>
>>58708038
Your "ugly" C++ gonna hit at least 3 errors u stupid fuck
>>
>>58708038
Why are you so ugly?
>>
>>58709501
>You cannot print objects
you just have an object to string function like you would in C++, then pass that string to printf. It requires two or three extra lines, but it's not really a hassle and is potentially a lot faster since you can avoid allocating from the heap.

>you cannot redirect the stream to something else, say a log or a file
that's what fprintf is for. Printf probably just calls fprintf internally in every implementation.

>You can effortlessly print stuff
I usually just use printf anyway because you separate the format from the data, so that you don't end up with the formatting being a pain in the ass to read because it's now spread over several lines. e.g.
cout << '{' << thing1.subobject << '\t-\t' << (bits_per_second / total_frame_size + processing_delay) << '}\n';
>>
>>58708902
Agreed, Python's indentation is cancer
>>
File: 1263274078409.jpg (18KB, 366x380px) Image search: [Google]
1263274078409.jpg
18KB, 366x380px
>>58708038
>#include<stdio.h>
>main()
>No line feed at the end of Hello World
>>
>>58709302
>>returning 0 instead of EXIT_SUCCESS
They are defined to be the same, why include a library just to write 0?
>>
>>58708038
It's not the brackets that are ugly, it's the "::". Fuck that shit desu senpai.
>>
>>58709844
>include a library
you're not including a library, you're including a header.

EXIT_SUCCESS and EXIT_FAILURE are better style. They clearly demonstrate what you are trying to do instead of using magic numbers. You also differentiate between whether you're using non-portable application specific exit codes or just signalling failure/success, when you use the macros.

Also, returning 1 on VMS actually indicates successful exit. I'm not sure what EXIT_SUCCESS is mapped to on that system. That's not really a concern in modern programming though.
>>
>>58708333
>for children
Anyone doing serious machine learning research is using python.
>>
>>58709995
Autism.
>>
File: 1479155298648.jpg (4KB, 171x211px) Image search: [Google]
1479155298648.jpg
4KB, 171x211px
>>58710058
>not wanting to use magic numbers is autism
>>
>>58708038
>OP can't even write a proper C++ main function
top kek
>>
C++ is very ugly but you're not really making the case for that.
>>
>>58710136
>exit status 0
>"magic number"
Not the guy you're responding to, but you're utterly retarded. Exit status 0 being success is defined in the C standard. EXIT_SUCCESS is ALWAYS defined to be 0, even on systems where 0 generally indicate failure. On these systems, the compiler has to create extra stub code in order to handle the fact that return 0 or exit(0) must indicate success.
>>
>>58710159
If you're using exit(0), you're probably using exit(1) somewhere else. hence why I specified EXIT_SUCCESS and EXIT_FAILURE.

Alternatively you could be using exit(0) and exit(EXIT_FAILURE) which is horrifying.
>>
>>58710195
>Alternatively you could be using exit(0) and exit(EXIT_FAILURE) which is horrifying.
It's just inconsistent, but it doesn't matter. EXIT_SUCCESS is always 0, EXIT_FAILURE is always 1.

It's just a preprocessor macro. Sure, it's being inconsistent, but it doesn't fucking matter.
>>
>>58708038
because operator overloading is magic
>>
>>58710205
>it doesn't fucking matter
Yes it doesn't. That's why it's called style.
>>
>>58708038
[include]#include <cstdio>[/include]

there you go
>>
>>58710218
I always use 0 and 1, that's a consistent style. There's no real reason to use EXIT_SUCCESS or EXIT_FAILURE and they're only still part of C because of legacy reasons.
>>
File: Screenshot_20170129_165046.png (27KB, 798x137px) Image search: [Google]
Screenshot_20170129_165046.png
27KB, 798x137px
>>58710205
>EXIT_FAILURE is always 1
I don't think that's correct.
>>
>>58710247
when C is ported to quantum computers and 1 will mean both failure and success then your code is fucked
>>
>>58710273
Yes, you are right. Only EXIT_STATUS is always 0. EXIT_FAILURE can be anything other than 0.
>>
>>58710276
>porting C to quantum computers
Quantum computers will only ever run Haskell.
>>
File: Screenshot_20170129_165553.png (21KB, 776x214px) Image search: [Google]
Screenshot_20170129_165553.png
21KB, 776x214px
>>58710301
>Only EXIT_STATUS is always 0
>>
>>58710205

Any return value that is non-zero is EXIT_FAILURE. It allows for implementation-defined fail states.
>>
>>58708359
>i don't care about portability

At least don't try to sell that garbage as an advantage.
>>
>>58710364
no, see
>>58710273
>>
masterrace reporting in
System.out.println("This is so beautiful");
>>
>>58708359

>high level and serious

C can be as high level as you want. It has literal billions of lines of library code with many having docs dating back to the 70's that can get your into your problem domain while still maintaining the performance expected of a language that is effectively an ASM abstraction layer.
>>
>>58710425

>masterrace

The only reason java can get people jobs is because it can be easily taught to pajeets and can be easily managed by PMs.
>>
>>58710433
C++ is better
you get the high level shit with the low level control
>>
>>58710530
and the high level security issues and bloat
>>
>>58708038
>no space after #include
>not specifying return type
>no return statement
>no \n
>random, pointless blank line
>no << endl or << flush;
>no using std::cout;

You are shit.
>>
>>58710544
>high level security
need more info on that

what makes C more secure?
>>
>>58710575
more specifically in C you can debug and find out the security issues where in C++ boost and similar libraries keep shitting CVE's and vulnerabilities weekly, this is not to say that all C libraries are secure, it's just they're more scrutinized and maintained, also the language itself has alot of unnecessary features that take unnecessary memory / cpu usage
>>
>>58709995
but nobody uses EXIT_SUCCESS anywhere else in any program.
It has the sole purpose of letting you return 0 on most platforms.
For a small application, you save 31 chars.
On larger applications, you would only use it if it is in your snippet.
>>
>>58708038
>angle brackets
>>
>>58710425
POO
>>
The answer is operator overloading. Also there's literally no reason not to use printf in c++ too.
>>
>>58710607
A lot of the C++ feature complexity is syntactic sugar.
In the end it compiles down to the same operations as an equivalent and more complex C code.

I saw a talk about this in cppcon, i'll try to find it.
>>
>>58710614
it's pretty common to call exit from 'holy shit everything is unrecoverably broken' handlers. That wouldn't just be in main.

Who the fuck cares about saving 31 chars? I'm also not sure how you'd save 31 chars from using 1 instead of EXIT_FAILURE.
>>
>>58710656
Something wrong anon?
>>
>>58708038
You're a shit programmer.
>>
>>58709158
Fun.
>>
>>58710607
You're full of shit.

>>58710735
https://www.youtube.com/watch?v=zBkNBP00wJE
This one?
>>
>>58710607
if you really care this much about security, you should be using Ada. Ada forces you to be secure, while C++ and C encourage you to do stupid shit.
>>
File: dbutils.png (19KB, 863x369px) Image search: [Google]
dbutils.png
19KB, 863x369px
Why is Object Pascal so beautiful?
>>
>>58708634
I was surprised the first time I saw Swift, it's kind of like Python (print statements, import statements, etc)
>>
Get on my level, faggots. Most aesthetic programming language incoming.

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
>>
>>58710374
C# can run on basically any PC platform, and any non-trivial program you write for the PC won't run on a non-PC anyways.
>>
>>58708038
>No \n
You have no right to hold any opinion on either of those languages while you don't even know them.
>>
>>58708536
Wtf? format strings are infinitely better than that garbage.

printf("This is a number: %i\n", 2);
>>
>>58712651
Glorious.
>>
>>58708038

It was modeled after your mom.
>>
>>58708113
I always lol at people with literal shit for brains trying to compare C++ and python.
>>
>>58709039
There are millions of ways to do things in many languages, it doesn't mean is the "correct way", specially after C++11
>>
>>58708536
You know you could've just googled alternative ways, right? Anyway, if your "experience" is a college class, your opinion about the language is irrelevant.
>>
>main
>return value
so what about concurrency?
>>
>>58708038
>he calls them angle brackets

Go write javascript Pajeet.
>>
File: 1484720275866.png (28KB, 470x241px) Image search: [Google]
1484720275866.png
28KB, 470x241px
>>58714640
C# is a ripoff language
>>
>>58715635
So what about not being a fucking retard?
>>
>>58712651
Hideous.
>>
>>58715635
What about it? Elaborate.
>>
list.push(a);
list.push(b);


list << a << b;


Qt supports both, but I tend to use latter almost exclusively now. Less brackets = less time spent figuring where each bracket belongs when reading the code.

Also

qDebug() << a << b << c;


This is pretty much the same as cout, only it adds spaces between its operands and adds a newline at the end. It's extremely convenient for debug output.
>>
Anything C++ can C can do too
Game_t *Game_New(bool init)
{
Game_t *game = malloc(sizeof(*game));

if (!game)
{
return NULL;
}
else if (init)
{
Game_Init(game);
}

return game;
}
>>
>>58716839
Anything C can do a trivial turing machine can do.
>>
>>58708359

My sides. Just billed a customer for 50K USD worth of riotously fast C code with a custom high level networking protocol and centralized database API. No other language could do this and run this lean on the customer's low power nodes.
>>
>>58709995
EXIT_SUCCESS is to return codes what NULL is to pointers. They both map to the constant 0, whether or not the actual implementation of the success code or the null pointer is actually 0. So exit(0) and exit(EXIT_SUCCESS) are strictly equivalent, independently of the platform.

EXIT_FAILURE on the other hand is implementation-defined, so you'd better use it as is for portability.
>>
>>58708536
You know, streams actually show their strength when you actually deal with streams, with indeterminate size.
Thread posts: 102
Thread images: 12


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.