Page 3 of 3

Re: C# Beginner

Posted: 05 May 2010, 19:30
by SwiftSpear
Licho wrote:You heard wrong :)
There is no reason why C# should be significantly slower than C++ - it compiles to native code anyway and is distributed in CPU neutral way - so its always optimized for CPU it runs at.
There is some overhead but some things are faster than C++ (like memory allocations).
Generally for modern applications you wont notice any speed difference. You get most gains/slowdowns from design changes, and in C# its easy to code advanced design in easily to read and maintain form. And for expensive stuff framework uses native OS libraries calls anyway.

You can use any windows framework you want with C#/.NET. I personally used Windows.Forms, WPF, GTK.
Of course native windows stuff (windows.forms or WPF) gives you biggest performance on windows systems.

As for productivity - I have never coded in anything as productive as C# for large scale applications. Untyped languages like Python imo can't compete for larger projects. Also wealth of .NET libraries and internet resources is gigantic.
If you want to code something simple it's probably better to go Python - but for larger things, no way.

Also C# is just one of .NET languages, in fact you can switch to any other and you still keep same runtime/framework there are even tools that auto convert them from one language to another - you can code in functional F#, VB, managed C++, IronPython, IronRuby, Pascal etc..
For example PlanetWars project had parts coded in F# which looks nothing like C#.
C# should be a little slower than C++ if your C++ is done in a bullet proof way. Garbage collector takes time to run. However, for most people, they will just have a bunch of leaks and the C# will run faster because of it after a few minutes. Also, C++ takes WAY longer to actually squeeze working code out of.

Re: C# Beginner

Posted: 05 May 2010, 19:35
by SwiftSpear
==Troy== wrote:
Satirik wrote:
Licho wrote:There is no reason why C# should be significantly slower than C++
==Troy== wrote:Saying that C# can be faster than C++
troy ... everything you say is boring and we all know c# is slower than c++ which is faster than c/assembler ...

Problem is that the slowness of C# is very downplayed in Lichos post, hence I allowed myself to simply go into the opposite direction.

Although I am glad I have not heard anyone yet promote VB here.


Edit : And btw, 2X slower isnt just "not significantly" its "tremendously" slower.
In the software design market 2 times slower, for most functions, is not significant. A company would rather wait a year and a half and buy twice as fast computers than recode a project in C++.

Some things have to be really really fast, sure. But development time, generally speaking, has higher costs than software execution time.

Also, it's easy to contrive examples that make the garbage collector work twice as hard. That doesn't mean the language is significantly slower. That means the C++ algorithm isn't being designed identically to the C# one. It's handling memory differently.

You shouldn't ever NEED to use C++ over C# unless you are coding games.

Re: C# Beginner

Posted: 05 May 2010, 19:36
by ==Troy==
SwiftSpear wrote: C# should be a little slower than C++ if your C++ is done in a bullet proof way. Garbage collector takes time to run. However, for most people, they will just have a bunch of leaks and the C# will run faster because of it after a few minutes. Also, C++ takes WAY longer to actually squeeze working code out of.

I agree on the last point. With the respect of code produced/ coder IQ the C# has huge advantage over C++. The issue is that automated garbage collector is not as effective as manual done at needed points. You also save time on checks of the memory when you code to know _specifically_ that there will be no conflict.

Memory-leak free C++ code will still run faster than C# code. Otherwise I am sure most of windows games will be written in C#. Edit : (posted right before you made your second post)

To add on to this, the problem is that it doesnt take that much longer to code C++ for a skilled developer. I know plenty of professional "old-school" programmers who are comfortable with both dev environments, and, given you have libs for both languages, they claim it doesnt take much longer to write in C++. once you develop the right habits.

Re: C# Beginner

Posted: 05 May 2010, 19:47
by hoijui
yeah Troy, you talk a lot of bullshit.

i am pretty sure you do not know C# or Java. everyone i know, that (really) knows C++ and either Java or C# would never say stuff like you do.
C++ is a language that has no right to exist, except for:
  • lot of existing C++ software that is still in use
  • coders that do not know any other high level language -> crippled view of the world
high- and low-level languages are called so, cause they are closer or further from the hardware, in a heavily abstracted view. if you imagine the hardware on the bottom (of course, cause it is heavy, while software has no weight), then C is closer to the ground (-> lower) then Java and C#.

C++ combines low level (C) with high level stuff (classes and such). this, its very core concept makes it fail. a key value of IT, and especially OO languages, is abstraction. in Java and C#, low level stuff HAS to be done by the VM (assembler, C) -> abstraction.
of course, you can also somehow include low level stuff in those languages, but it is not easy, and it naturally appears ugly; you try to prevent it as much as possible. And of course you could abstract all low level stuff into classes dedicated to that, in C++, but it is not done, cause it is easier to just write that stuff right in the file where you are.

The most brilliant coders back then just saw, that C++ is fail, and they started creating other languages, not to get market share, to create a hype... but cause the world was in need of it.

if you need to code a GUI app, which needs to do low level stuff not possible in Java or C#, then code only the really low level stuff in C, and everything else in Java or C# (or python... whatever). By the very principle of "abstraction is good", this will lead to a more an application with less bugs, and coded in less time.

C++ is like the brown-coal of computer languages, spices with quicksilver and whatnot, burnt to make energy.

Re: C# Beginner

Posted: 05 May 2010, 19:57
by ==Troy==
hoijui Although I mostly agree with you, you are missing simple issue of dependencies. Especially with C#.

If you need to code for a chip, or for ANYTHING which doesnt support or have C# VM, you will be forced to code in a "lower level" language. Best out of those is C++, for different reasons.


When you resort to coding in C# you create a program which is stupidly dependant on .net framework, requires the user to download and separately manage the .net package, having to have multitude of different .net packages simply because you cant change documented bugs (they call them features nowadays).

As we already agreed that for the OP's application the C# might as well do, or any other VM language.

The point I am trying to make is that VM languages are VERY restricted, considerably slower, and are very specialised. While C++ code, whilst being readable, is easily cross-platform and very flexible.

Re: C# Beginner

Posted: 05 May 2010, 20:26
by Tobi
Pxtl wrote:I assume you're working in Visual Studio

While MS's documentation sucks from the mile-high distance, it's excellent up-close. You can hit ctrl-space when on any object and get a listing of it's members and can walk through them and see tooltips explaining usage and whatnot.
The other way round IMO.

From a mile high it looks ok, but when I want to know some detail about some method, it is never in the documentation. I always have to open up .NET libs in reflector (or run some experiments) if I want to know what they really do.

Just to name some examples: usually it isn't specified what exceptions may be thrown in what circumstances, and only recently they've started specifying runtime complexity for algorithms/data structures in MSDN documentation.
Licho wrote:As for productivity - I have never coded in anything as productive as C# for large scale applications. Untyped languages like Python imo can't compete for larger projects. Also wealth of .NET libraries and internet resources is gigantic.
If you want to code something simple it's probably better to go Python - but for larger things, no way.
Common mistake.

Python (and other languages e.g. ruby, lua) is actually strongly (and dynamically) typed.

(Compare to e.g. PHP, which is weakly & dynamically typed, or C/C++/C#/Java which are strongly & statically typed)

The only language I can think of right now that is untyped is maybe batch/shell script.
Troy wrote: I think you are dead wrong here.

The same way Assembler is specialised to be "machine code" you effectively get a lot less processing power used up for redundant checks where you do not need them.
I've seen a few cases already where equivalent C code beat the heck out of hand-optimised assembler code. So apparently this extra necessary processing power is more then compensated for by the advanced optimisation techniques the compiler can apply throughout ALL your code. (Whereas in hand optimised assembler you'll optimise only the hot spots.)

Also note that JIT compiling means the compiler can use all features of the current CPU, as when doing AOT compiling like for C++ you can use only the common subset of all CPUs you are targetting. As compiler technology advances and people keep using old hardware longer, this can move C# (and other JIT compiled languages) ahead while it can keep C++ back.

With regards to garbage collection: although the GC cycle takes some CPU, realise that with a GC memory allocation can be immensely simplified (down to only a few machine code instructions for short term / first generation heap).

Also do note that 2x slower is quite insignificant if you realise many code is nowadays written in languages that are easily 10-100x slower than C/C++. ;-)
hoijui Although I mostly agree with you, you are missing simple issue of dependencies. Especially with C#.

If you need to code for a chip, or for ANYTHING which doesnt support or have C# VM, you will be forced to code in a "lower level" language. Best out of those is C++, for different reasons.
Such things are already moving towards Java more and more. (which I'd say is approximately the same level language as C#)

(Obviously on such platforms they have only the language, and not the (complete) platform. Probably C# could be ported to such platforms in a similar way.)

Re: C# Beginner

Posted: 05 May 2010, 20:41
by hoijui
for chips, use C, not C++.
for PC, use .. anything but C++.
most people have a JVM installed, under windows, most have .NET, and on linux mono is really not hard to install (package manager - search mono - install).

comparing bugs/functionality of the JVM and .NET to C++ applications...
nuff said

JVM and C# being very restricted is just plain false. even IF you need to do stuff you can not do natively there, you can still resort to doing it in C or assembler. This is not needed often, and when it is, it is usually cause you have to communicate with C/C++ software, not for hardware access.

Of course it makes little sense to use C# on chips where it wont run (...). but this was never at stake here. you just have this in mind and take it as a base here. this is only about PCs.
Burning brown-coal since 1979
you are killing little... something kittens with it!!

Re: C# Beginner

Posted: 05 May 2010, 22:39
by Teutooni
Drifting a bit off topic, but I guess Wisse doesn't mind...
hoijui wrote:C++ is a language that has no right to exist
Still haven't seen a single good reason for C# to exist either. Hate towards C++ is understandable - it's easy to write horrible unmaintainable code with gazillion bugs because of the philosophy that no unnecessary safety checks are made and many of the tools are pretty risky in unskilled hands (pointers or inheritance comes to mind).

I'm not saying C++ is a good language, I say it has its uses (for combining performance critical parts with GUI stuff for example, i.e. games). I'm also saying C# doesn't have a valid use which Java, Python, C or C++ couldn't do better. Prove me wrong! :P

Re: C# Beginner

Posted: 06 May 2010, 00:26
by Licho
And I'm just saying you are nub who needs to spend many years coding in them before making such statements.

Re: C# Beginner

Posted: 06 May 2010, 14:37
by SwiftSpear
Teutooni wrote:Drifting a bit off topic, but I guess Wisse doesn't mind...
hoijui wrote:C++ is a language that has no right to exist
Still haven't seen a single good reason for C# to exist either. Hate towards C++ is understandable - it's easy to write horrible unmaintainable code with gazillion bugs because of the philosophy that no unnecessary safety checks are made and many of the tools are pretty risky in unskilled hands (pointers or inheritance comes to mind).

I'm not saying C++ is a good language, I say it has its uses (for combining performance critical parts with GUI stuff for example, i.e. games). I'm also saying C# doesn't have a valid use which Java, Python, C or C++ couldn't do better. Prove me wrong! :P
C# could be said to be objectively better for independent developers working on direct X games than any of those alternatives.

"better" is also subjective... If you need multi platform support, surely java is "better" but it's probably not faster. C is horribly antiquated and should probably not be used for anything any more. C++ is great and powerful if you have tonnes of time to work with it or are heavily experienced, Python is cool, but it doesn't have as much work put behind library development and stuff like that go along with it, and consequently it doesn't compete for most functions. Java has great multiplatform support, and is okish for speed... but being realistic, anything high performance probably has to avoid java.

It seems to me there are alot of things you would want to do in C#... With an infinite budget and the ability to bring on any coder in the world, ya, you probably wouldn't use C#. But if you're a software developer learning stuff, you can do almost anything in C# fairly quickly and in the end it will preform decent.

It's a honda civic language. It might not go off road into lunix and mac systems without some serious stress, it might not be a luxury sports car zipping around, but anywhere there is a road it can get you there, and it's going to probably cost alot less while it's doing it.

Re: C# Beginner

Posted: 06 May 2010, 15:32
by hoijui
C still has its right to exist. for really low level stuff like hardware access, writing VMs, or on small chips.
C++ does NOT have such a niche, if not for people used to it (no valid argument). if you need speed and GUI, use C for the performance relevant stuff, and a nice high level language for the GUI.

Re: C# Beginner

Posted: 16 May 2010, 22:03
by t0rb3n
http://yosefk.com/c++fqa/ is a quite interesting lecture about c++ ...

Re: C# Beginner

Posted: 16 May 2010, 23:03
by SwiftSpear
==Troy== wrote:hoijui Although I mostly agree with you, you are missing simple issue of dependencies. Especially with C#.

If you need to code for a chip, or for ANYTHING which doesnt support or have C# VM, you will be forced to code in a "lower level" language. Best out of those is C++, for different reasons.


When you resort to coding in C# you create a program which is stupidly dependant on .net framework, requires the user to download and separately manage the .net package, having to have multitude of different .net packages simply because you cant change documented bugs (they call them features nowadays).

As we already agreed that for the OP's application the C# might as well do, or any other VM language.

The point I am trying to make is that VM languages are VERY restricted, considerably slower, and are very specialised. While C++ code, whilst being readable, is easily cross-platform and very flexible.
VM languages tend to have far fewer dependency issues than C++. C++ is not a trivial language to compile on many hardwares. If you can get C++ code to compile for a hardware platform, you can run a java or C# VM on it. C++ isn't the lowest level language out there. Alot of hardware platforms just can't use it.

Granted, C# might not be the best champion of cross compatibility, but cell phones run java... VM languages need not be something to fear.

Re: C# Beginner

Posted: 17 May 2010, 02:48
by Pxtl
hoijui wrote:C still has its right to exist. for really low level stuff like hardware access, writing VMs, or on small chips.
C++ does NOT have such a niche, if not for people used to it (no valid argument). if you need speed and GUI, use C for the performance relevant stuff, and a nice high level language for the GUI.
Not only that, but C is an easy language to implement the compiler for, compared to all newer popular languages. When you've made a brand-new platform, what's the first thing you need on it? A C compiler. Then you can use that C compiler to compile more complicated execution platforms. C++ (particularly with the new 11 extensions) is a nightmare to implement, comparatively speaking.

That said, C++ is practically _the_ language for game engine development. Why? Because game engine development is a field where you really can't sacrifice performance _anywhere_, but at the same time your project will grow to be enormously cumbersome if you use classic C.

Outside of the Gaming field (and similar large-scale high perf apps) C++ is way, way, way too complex and nasty to use.

Re: C# Beginner

Posted: 17 May 2010, 10:41
by Tobi
SwiftSpear wrote: VM languages tend to have far fewer dependency issues than C++. C++ is not a trivial language to compile on many hardwares. If you can get C++ code to compile for a hardware platform, you can run a java or C# VM on it. C++ isn't the lowest level language out there. Alot of hardware platforms just can't use it.

Granted, C# might not be the best champion of cross compatibility, but cell phones run java... VM languages need not be something to fear.
Not really in my experience, if you actually code some Java for a chip that directly executes Java bytecode you'll have similar dependeny issues as when you'd compile C++ for a similar chip that executes whatever bytecode. (the thing doesn't magically have all Java libs you want available)

That said, on normal desktops/servers languages more modern than C++ often do have a nice ecosystem for installing packages (e.g. maven for Java, ruby gems for ruby, PyPI for python, CPAM for perl, etc.), but I think this is completely uncorrelated to whether or not the language uses a VM :-) (C# doesn't have such tools/ecosystem, right?)

Also any hardware platform that really can not be programmed with C++ can not be programmed in any turing complete language, as they are all equivalent and can theoretically be implemented in each other.
(Or did you just mean that the manufacturer doesn't ship a ready made C++ compiler in the box? ;-))

(As a practical example, realise that C++ can be compiled into C, as early C++ compilers did, so if you can program your chip with C then you can program it with C++.)