Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

878021 Posts in 32900 Topics- by 24324 Members - Latest Member: Fi_designer

May 21, 2013, 02:55:32 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)The happy programmer room
Pages: 1 ... 185 186 [187] 188 189 ... 227
Print
Author Topic: The happy programmer room  (Read 263471 times)
Crimsontide
Level 3
***


View Profile
« Reply #2790 on: August 11, 2012, 06:45:52 PM »

C is far more elegant and uncluttered than C++

Funny, I have issues with C++, but inheritance I thought was one of the few things done well in C++.  But to each his own, in the end it all boils down to a bunch of binary anyways Wink
Logged
chessguy
Level 0
*


View Profile
« Reply #2791 on: August 11, 2012, 07:43:25 PM »

I just figured out you can have custom data types (struct, class, union) within each other...

Well, probably not for unions... for the others, though. And then they get ananimous, to. So confusing.

Oddly... I first came across this concept in a Java book I read only earlier. I was looking up what extern did and decided to search up unions as well. Hrm...

Not sure if I am happy or not... this might be useful if I figure it out :\

On another note, I went over and configured the coloring for my IDE (syntax coloring, I should say), and I like it  Smiley
Logged
impulse9
Level 5
*****



View Profile WWW
« Reply #2792 on: August 12, 2012, 01:23:50 PM »

Just implemented clipboard in my editor .. yay!  Gomez
Logged

harkme
Level 1
*


Surprise!


View Profile Email
« Reply #2793 on: August 12, 2012, 07:25:06 PM »

C is far more elegant and uncluttered than C++

Seems to me like you're confusing inelegance and clutter with being feature-rich. There is a lot to C++, yes, but if you learn the tools effectively, they can make your life a million times easier. I'm completely confused at ThemsAllTook rolling out his own object-oriented system in C. He's only setting himself up for code that is harder to read, less flexibility than the C++ implementation, and likely less performance. If you don't want to use certain C++ features, don't use them. Write your same C code and use C++ specific features where you need them. There is no penalty for not using a feature in C++.

C99 and C11 also have quite a few really neat features that C++ lacks.

Such as...?
Logged

Liosan
Level 2
**


View Profile
« Reply #2794 on: August 13, 2012, 01:09:38 AM »

C99 and C11 also have quite a few really neat features that C++ lacks.
Such as...?
Struct initialization:
Code:
MY_STRUCT a = { .flag = true, .value = 123, .stuff = 0.456 };

Liosan
Logged

rivon
Level 10
*****



View Profile
« Reply #2795 on: August 13, 2012, 01:47:43 AM »

C99 and C11 also have quite a few really neat features that C++ lacks.

Such as...?
I've just read this whole page and I didn't find anything much useful. Mostly just syntactic sugar. I've definitely not found any "really neat feature".

Edit: Though the page only deals with C99 vs C++98. Maybe there is something new in C11.
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW Email
« Reply #2796 on: August 13, 2012, 04:58:23 AM »

C99 and C11 also have quite a few really neat features that C++ lacks.

Such as...?
I've just read this whole page and I didn't find anything much useful. Mostly just syntactic sugar. I've definitely not found any "really neat feature".

Edit: Though the page only deals with C99 vs C++98. Maybe there is something new in C11.

Designated initializers for structs and arrays (mentioned previously) kick ass.

Code:
struct Point p = { .x = 5, .y = 6};
int a[5] = { [0] = 5, [1] = 6 };

C99 has a number of optimization enhancements that C++ lacks, primarily restrict and static array parameter bounds.

Code:
void f(int *restrict p1, int *restrict p2); // The compiler may assume that p1 and p2 do not alias the same object.

void g(int a[static 10]); // The compiler may assume that a contains at least 10 elements.

void h(int a1[restrict 5], int a2[restrict 10]); // The compiler may assume that a1 contains at least 5 elements, a2 contains at least 10, and a1 and a2 are not the same array.

These guarantees are of great interest to the optimizer.  In my most basic usages they generate significantly smaller and faster code.

Native complex number support. (I haven't really played with this, so I can't say much more.  I do know it's one of the major strengths of Fortran though)

Variadic macros (adopted by C++11).

Variable length arrays.

Code:
void f(unsigned size)
{
    int array[size]; // Variable length array.
}

VLAs offer much better performance than heap-based dynamic arrays, because they have a known start address and are created and destroyed with the function's stack frame.

This is just C99 stuff, my knowledge of C11 is limited right now, but the new threading constructs are definitely of interest.
Logged

Franchise - The restaurant wars begin!

What would John Carmack do?
rivon
Level 10
*****



View Profile
« Reply #2797 on: August 13, 2012, 09:38:51 AM »

Designated initializers for structs and arrays (mentioned previously) kick ass.

Code:
struct Point p = { .x = 5, .y = 6};
int a[5] = { [0] = 5, [1] = 6 };
I don't see how they kick ass. If anything, they just shorten the code by a few lines (unnecessary) and they make the code more unreadable.

Native complex number support. (I haven't really played with this, so I can't say much more.  I do know it's one of the major strengths of Fortran though)
C++ has complex template in <complex>. Though if you were really serious with complex mathematics, you would probably use some specialized library for it instead of using either the C or the C++ complex numbers.
Logged
ThemsAllTook
Moderator
Level 8
******


Alex Diener


View Profile WWW
« Reply #2798 on: August 13, 2012, 10:29:53 AM »

I'm completely confused at ThemsAllTook rolling out his own object-oriented system in C. He's only setting himself up for code that is harder to read, less flexibility than the C++ implementation, and likely less performance. If you don't want to use certain C++ features, don't use them. Write your same C code and use C++ specific features where you need them. There is no penalty for not using a feature in C++.

You're right about the drawbacks of my system. I've considered switching to C++ many times. It's mostly a lot of little annoyances stopping me. The biggest thing is that I use automatic typecasts to and from void * absolutely everywhere. I'd have to either clutter up my code with a huge number of explicit typecasts to get it to compile as C++, or fundamentally change paradigms in a lot of places. The C++ mentality is "if you're using void *, you're doing it wrong", which directly clashes with my way of coding. From what I understand, compilation and linking is also much slower with C++, so I theoretically get quicker modify/run turnaround times with C.
Logged
Graham.
Level 10
*****



View Profile WWW
« Reply #2799 on: August 13, 2012, 10:33:48 AM »

Designated initializers for structs and arrays (mentioned previously) kick ass.

Code:
struct Point p = { .x = 5, .y = 6};
int a[5] = { [0] = 5, [1] = 6 };
I don't see how they kick ass. If anything, they just shorten the code by a few lines (unnecessary) and they make the code more unreadable.

That's debatable.
Logged

rivon
Level 10
*****



View Profile
« Reply #2800 on: August 13, 2012, 12:39:56 PM »

From what I understand, compilation and linking is also much slower with C++, so I theoretically get quicker modify/run turnaround times with C.
It isn't slower. Maybe template stuff might be slow but otherwise, I think that C++ compiling would surely be faster than your hacked up objects.

Designated initializers for structs and arrays (mentioned previously) kick ass.

Code:
struct Point p = { .x = 5, .y = 6};
int a[5] = { [0] = 5, [1] = 6 };
I don't see how they kick ass. If anything, they just shorten the code by a few lines (unnecessary) and they make the code more unreadable.

That's debatable.
Maybe in the case of the example it might look pretty, but the moment you start adding more struct member variables with longer names it will get cluttered very fast.
It's like with the ternary conditional operator chains.
Logged
Graham.
Level 10
*****



View Profile WWW
« Reply #2801 on: August 13, 2012, 12:58:43 PM »

I agree. If there is relevant uniqueness between the struct members for the uniqueness of their names to be significant then that syntax would be bad.

But if it's just like a bunch of values then its good.

I don't use ternary usually.
Logged

Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW Email
« Reply #2802 on: August 13, 2012, 04:52:19 PM »

From what I understand, compilation and linking is also much slower with C++, so I theoretically get quicker modify/run turnaround times with C.
It isn't slower. Maybe template stuff might be slow but otherwise, I think that C++ compiling would surely be faster than your hacked up objects.

Designated initializers for structs and arrays (mentioned previously) kick ass.

Code:
struct Point p = { .x = 5, .y = 6};
int a[5] = { [0] = 5, [1] = 6 };
I don't see how they kick ass. If anything, they just shorten the code by a few lines (unnecessary) and they make the code more unreadable.

That's debatable.
Maybe in the case of the example it might look pretty, but the moment you start adding more struct member variables with longer names it will get cluttered very fast.
It's like with the ternary conditional operator chains.

I find this feature absolutely indispensable when working with the Windows API and its gigantic structs.  Here's a an example from one of my projects:

Code:
    WNDCLASSEX class_info =
    {
        .cbSize = sizeof(WNDCLASSEX),
        .style = 0,
        .lpfnWndProc = wnd_proc,
        .cbClsExtra = 0,
        .cbWndExtra = DLGWINDOWEXTRA + sizeof(struct MainWindowData*),
        .hInstance = GetModuleHandle(0),
        .hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON)),
        .hCursor = LoadCursor(0, IDC_ARROW),
        .hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1),
        .lpszMenuName = 0,
        .lpszClassName = class_name,
        .hIconSm = 0
    };

This is one of the smaller Windows structures, this ability becomes even more valuable with the REALLY big ones.

Another interesting aspect is that members you don't initialize are set to 0.  This allows you to do a sort of staggered initialization of arrays.

Code:
int array[10] = { [1] = 5, [6] = 27 }; // Everything else is 0.

I use this quite a lot.  I don't do it with the WinAPI structs because I'm frequently going back and adding things and I don't want to have to go look up the member names again (lazy, I know).
Logged

Franchise - The restaurant wars begin!

What would John Carmack do?
Liosan
Level 2
**


View Profile
« Reply #2803 on: August 13, 2012, 09:52:42 PM »

From what I understand, compilation and linking is also much slower with C++, so I theoretically get quicker modify/run turnaround times with C.
It isn't slower. Maybe template stuff might be slow but otherwise, I think that C++ compiling would surely be faster than your hacked up objects.
In theory, yes. But if you're using Visual Studio, and #include, let's say, <string>, then because of the explicit template implementations in that header the compiler has to generate code for the string in each translation unit, then the linker has to remove each of the superflous weak symbols and leave only one. It IS slower. g++ has it's quirks too, not only VS.

Liosan
Logged

Nix
Level 10
*****



View Profile
« Reply #2804 on: August 13, 2012, 10:04:39 PM »

From what I understand, compilation and linking is also much slower with C++, so I theoretically get quicker modify/run turnaround times with C.
It isn't slower. Maybe template stuff might be slow but otherwise, I think that C++ compiling would surely be faster than your hacked up objects.

You mean structs and functions? How would that be slow to compile?

Edit: a lot of you seem to be surprised by the use of objects in C. This pdf is basically the bible on the subject: http://www.cs.rit.edu/~ats/books/ooc.pdf. It really just comes down to preference. Neither language is objectively superior (heh pun heh). The only difference is that you have to roll your own solution if you want classes in C, but the end product can be as powerful or moreso than C++'s built-in object system.

Edit 2: Here is Linus Torvalds' entertaining rant on the subject: http://harmful.cat-v.org/software/c++/linus
« Last Edit: August 13, 2012, 10:16:52 PM by Nix » Logged
Pages: 1 ... 185 186 [187] 188 189 ... 227
Print
Jump to:  

Theme orange-lt created by panic