Page 4 of 5 [ 72 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

EtotheC
Blue Jay
Blue Jay

User avatar

Joined: 23 Jun 2009
Gender: Male
Posts: 89

24 Jun 2009, 2:30 pm

EarlPurple wrote:
No doubt it performed badly because it was badly written, not because it was in C++.


Ahh the perils of a language that gives so much systems control to the programmer...

C I love thee so



EarlPurple
Snowy Owl
Snowy Owl

User avatar

Joined: 4 Jun 2009
Age: 60
Gender: Male
Posts: 162
Location: London, UK

24 Jun 2009, 2:56 pm

You have all that in C++ too for when you need it.



EtotheC
Blue Jay
Blue Jay

User avatar

Joined: 23 Jun 2009
Gender: Male
Posts: 89

24 Jun 2009, 3:01 pm

EarlPurple wrote:
You have all that in C++ too for when you need it.


C++ = Extended C

Yes I know, it was the OO sucessor to C



thatguy03178
Emu Egg
Emu Egg

User avatar

Joined: 15 Dec 2008
Age: 36
Gender: Male
Posts: 8
Location: Not here

26 Jun 2009, 5:18 pm

The first programming language I learned was Java in collage. Some other languages I learned at collage were C#, C, and Flex/Actionscript.



Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 61
Gender: Male
Posts: 1,788
Location: London (UK)

26 Jun 2009, 11:41 pm

EarlPurple wrote:
Dussel wrote:
lau wrote:
EarlPurple wrote:
C++ has to offer 4 things that C doesn't that make it easier to use:
    EarlPurple wrote:
    - Automatic destructors
    At a memory/speed cost.
    EarlPurple wrote:
    - Exceptions
    At a memory/speed cost.
    EarlPurple wrote:
    - Polymorphism i.e. virtual functions.
    At a memory/speed cost.
    EarlPurple wrote:
    - templates, in particular for collections
    At a memory/speed cost.


I've run into this once extremely: I wrote a program which dealing with a vast amount of very small data sets (10^7 of a few kB each). Replacing the std-lib, virtual methods and templates with C-Style pointer increased the speed drastically (factor 10 and more).

Most speed consuming are virtual methods of classes which are only determinate during runtime.


I'd be interested to see your C++ code that performed so badly. No doubt it performed badly because it was badly written, not because it was in C++.

std::vector can be slower than straight arrays because of its initialisation. It is not the best to use for large sets of data if it needs to be grown because reallocating is O(N) and also because it requires a contiguous buffer. std::deque should be used instead.


Neither - The best way to handle such data is still a plain list of pointers. The data do not need to be in one array, but can be atomistic within the Heap, adding, deleting, even sorting does not influence the location of the elements in the Heap. It is flexible, you can work well list of pointers to pointers, etc. pp.

But: The main problem with performance an C++ is mostly the pure virtual methods, which are only to determinate in runtime.

EarlPurple wrote:
I do agree that exceptions would be better implemented if there were no class hierarchy. One exception type would suffice.


It would be fine, if there would be kind of strict data type for exception (like in ADA, which has here much stricter concepts). The type-muddling of C++, mostly inherited from C, is with no means helpful at all.



gamefreak
Veteran
Veteran

User avatar

Joined: 30 Dec 2006
Age: 35
Gender: Male
Posts: 1,119
Location: Citrus County, Florida

27 Jun 2009, 12:03 am

Python all the way. Its the one I'm most fluent in.



Pobodys_Nerfect
Veteran
Veteran

User avatar

Joined: 10 Mar 2008
Age: 46
Gender: Male
Posts: 600
Location: New Zealand

27 Jun 2009, 1:00 am

0_equals_true wrote:
Does anyone hate it when braces are bellow the control statement rather then the same line. It drives me nuts.

I think it was put on the same line in some text books initially, to save paper.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 76
Gender: Male
Posts: 9,798
Location: Somerset UK

27 Jun 2009, 7:00 am

I hate coding practices that convert a succinct, graspable routine into several pages of pointless whitespace.

If you cannot fit a complete route into less than 24 lines of text, you have probably designed and written it all wrong.


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Meta
Toucan
Toucan

User avatar

Joined: 15 Jun 2009
Age: 50
Gender: Male
Posts: 276

27 Jun 2009, 8:01 am

In a some what chronological order:

Bash, Pascal, Emacs Lisp, Hugs/Haskell, C, Java, Fortan, Prolog, Perl, Scheme, Common Lisp, Ruby

Most of the code I currently write is in Emacs Lisp or Common Lisp.

Future special projects: Objective-C, SmallTalk, Python



LostInEmulation
Veteran
Veteran

User avatar

Joined: 10 Feb 2008
Age: 42
Gender: Female
Posts: 2,047
Location: Ireland, dreaming of Germany

27 Jun 2009, 8:35 am

lau wrote:
Code:
: xx cr 3 0 do 2 0 do ." Hip, " loop ." Hurray!" cr loop ; xx

8O :) :D


_________________
I am not a native speaker. Please contact me if I made grammatical mistakes in the posting above.

Penguins cannot fly because what cannot fly cannot crash!


Fuzzy
Veteran
Veteran

User avatar

Joined: 30 Mar 2006
Age: 52
Gender: Male
Posts: 5,223
Location: Alberta Canada

27 Jun 2009, 10:16 am

gamefreak wrote:
Python all the way. Its the one I'm most fluent in.


Thats funny. I am learning python as you are learning linux.


_________________
davidred wrote...
I installed Ubuntu once and it completely destroyed my paying relationship with Microsoft.


jmr
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 25 Jun 2009
Age: 45
Gender: Male
Posts: 50

29 Jun 2009, 12:06 am

Meta wrote:
Most of the code I currently write is in Emacs Lisp or Common Lisp.

Code:
'((my other car)
  (is a cdr))

;)



EarlPurple
Snowy Owl
Snowy Owl

User avatar

Joined: 4 Jun 2009
Age: 60
Gender: Male
Posts: 162
Location: London, UK

29 Jun 2009, 2:42 pm

Dussel wrote:
EarlPurple wrote:
Dussel wrote:
lau wrote:
EarlPurple wrote:
C++ has to offer 4 things that C doesn't that make it easier to use:
    EarlPurple wrote:
    - Automatic destructors
    At a memory/speed cost.
    EarlPurple wrote:
    - Exceptions
    At a memory/speed cost.
    EarlPurple wrote:
    - Polymorphism i.e. virtual functions.
    At a memory/speed cost.
    EarlPurple wrote:
    - templates, in particular for collections
    At a memory/speed cost.


I've run into this once extremely: I wrote a program which dealing with a vast amount of very small data sets (10^7 of a few kB each). Replacing the std-lib, virtual methods and templates with C-Style pointer increased the speed drastically (factor 10 and more).

Most speed consuming are virtual methods of classes which are only determinate during runtime.


I'd be interested to see your C++ code that performed so badly. No doubt it performed badly because it was badly written, not because it was in C++.

std::vector can be slower than straight arrays because of its initialisation. It is not the best to use for large sets of data if it needs to be grown because reallocating is O(N) and also because it requires a contiguous buffer. std::deque should be used instead.


Neither - The best way to handle such data is still a plain list of pointers. The data do not need to be in one array, but can be atomistic within the Heap, adding, deleting, even sorting does not influence the location of the elements in the Heap. It is flexible, you can work well list of pointers to pointers, etc. pp.

But: The main problem with performance an C++ is mostly the pure virtual methods, which are only to determinate in runtime.

EarlPurple wrote:
I do agree that exceptions would be better implemented if there were no class hierarchy. One exception type would suffice.


It would be fine, if there would be kind of strict data type for exception (like in ADA, which has here much stricter concepts). The type-muddling of C++, mostly inherited from C, is with no means helpful at all.


If there were one exception type it would be a strict data type. It would most likely have the attributes of a number and a text denoting the error reason and ideally would have something that C++ exceptions do not have which is a call-stack although it may be something you would have for debugging only or possibly disable because of the overhead.

Plain lists of pointers still have to point to something and doing lots of allocating is worse performance than allocating a block then filling them, which is what std::deque does. I assume you mean a typed pointer array and you can have those with vector and deque too if you want. With regards to sorting, it has been shown that if you can inline the comparison then std::sort heavily outperforms the C qsort function.

Pure virtual functions are there to program a concept, one called polymorphism. The C equivalent is function pointers. Are you sure that function pointers are slower than virtual functions because I doubt they are. With a pure virtual function the compiler will ensure it is implemented too.



jmr
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 25 Jun 2009
Age: 45
Gender: Male
Posts: 50

29 Jun 2009, 3:39 pm

You guys better be careful how deeply you nest those recursive quotes; you might overflow the BBCode interpreter's stack!



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 76
Gender: Male
Posts: 9,798
Location: Somerset UK

30 Jun 2009, 4:55 am

You make a lot of claims for C++. E.g.

EarlPurple wrote:
... With regards to sorting, it has been shown that if you can inline the comparison then std::sort heavily outperforms the C qsort function. ...

Does it outperform it for:
  1. The empty set.
  2. Small numbers of items.
  3. Large numbers of items that are almost sorted to start with.
  4. A number of items that is too large for it to hold in real memory, because of its overheads.

In any case, here you are not comparing C with C++, you are only comparing one fixed library routine with the C++ approach.

There is no such thing as a "best" language. Indeed, the whole concept of one language even being "better" than another is dependent on knowing what hardware it will be running on, what compiler and what library code. I have seen some horrendously buggy C compilers.

Anything written in C++ can be hand-translated into C, and made more efficient. Admittedly that would not a simple process, and it could very time consuming, but it is true.

Anything written in C can be almost trivially hand-translated into C++. I've done exactly this quite often, It is a simple process and quick. However, it will likely be very inefficient, and any attempt to improve the code by tinkering with it will be challenged by the overheads inherent in C++.

(Although the code could, of course, be vastly "generalised"... but that is likely to be completely irrelevant.)


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Meta
Toucan
Toucan

User avatar

Joined: 15 Jun 2009
Age: 50
Gender: Male
Posts: 276

30 Jun 2009, 5:33 pm

I know that Objective-C is a superset of C; but I thought that C++ is not: In general a proper C program will not be a proper C++ program.

The late Eric Naggum said: If you can't outperform C in Common Lisp, you're too good at C.
;)