|
|
|
date: Thu, 17 Jul 2008 17:31:36 -0500,
group: microsoft.public.dotnet.languages.csharp
back
Re: learn C++ or C#
"Arne Vajhøj" ha scritto nel messaggio
news:487fdc67$0$90274$14726298@news.sunsite.dk...
> First I will make a prediction: the .vc guys will suggest C++ and
> the .csharp guys will suggest C#.
>
> :-)
I'm a .vc guy :-)
> If you want to write general business apps, then I will suggest C#.
I agree with that.
> If you have special requirements for real time, embedded, device
> driver programming and similar then go for C++.
Moreover, if you want to build Windows shell extensions, you should use C++.
If you want crossplatform code, you should use C++ (with proper libraries
like wxWidgets for the GUI).
If you want to build small .exe's easy to deploy (no need of huge runtime to
distribute), you should use C++ (with CRT/MFC/ATL statically linked).
If you learn C++ first, then moving to C# is a very easy path, as others
wisely wrote.
Instead, the opposite is not true.
Both languages have pro's and con's: choose the better tool for your
particular job.
Giovanni
date: Fri, 18 Jul 2008 10:17:09 +0200
author: Giovanni Dicanio gdicanio@_NOSPAM_email_DOT_it
Re: learn C++ or C#
In article news:, Daniel wrote:
> If I haven't made substantial investment in either C++ or C#, which
> language would the experts recommend I become well acquainted with?
It depends what you want to do, and where you want to do it.
C++ is the more powerful language but there is more to learn, C# is
relatively simple but less powerful. OTOH there are more productivity
tools for C# (largely because it has a simpler syntax, so the tools are
easier to write).
C++ can be used to write software for a huge range of systems -- not
only Windows but also Mac, linux and others (including mini and
mainframe computers, and embedded systems). C# targets a virtual machine
architecture, so C# programs can run only on computers for which such a
runtime (a JIT compiler or an interpreter) is available -- that means
Windows, certainly, and platforms that support Mono (an Open Source
NET-compatible runtime); but not nearly so many as can run C++
programs.
C++ can be used to write system-level code: operating systems, device
drivers, etc.. Although there are research projects and proof of concept
implementation that use C# for these things, current C# implementations
do not allow C# to be used for this kind of work with mainstream OSes --
you can't write even a Windows device driver in C#. If you want to do
driver work then choose C++ (or even C).
A good implementation plan is to write your back-end code -- the
business logic of your application -- in a fast portable language (such
as C++) so that it can be built to run on the maximum possible number of
platforms, and then to write a GUI wrapper around it for each platform
on which you want to ship ... you might choose to write such a GUI
wrapper in C# for a Windows version of your software, though other
possibilities (including VB, Java, Python, etc) exist.
Alternatively you could write your application logic in a webserver
format and use your platform's browser for the GUI, which would save you
writing any platform-specific GUI code at all.
Personally, I usually write the application back-end in C++ and then
write the Windows-specific GUI wrapper in C++ using MFC ... but then I'm
from a C++ background and I just do what comes naturally.
Cheers,
Daniel.
date: Fri, 18 Jul 2008 10:36:50 +0100
author: Daniel James
Re: learn C++ or C#
Daniel wrote:
> If I haven't made substantial investment in either C++ or C#, which language
> would the experts recommend I become well acquainted with?
Daniel:
As you are posting in dotnet groups, you should know that there are actually
three languages
C++
C#
C++/CLI
Up to now you have been using C++/CLI, which is the wrong choice if you want to
write GUI Windows applications, because Microsoft no longer recommends C++/CLi
for writing GUI .NET applications.
Assuming that you want to write GUI applications for Windows, you need a library.
If you use native C++, you will probably want to use the MFC library (which does
not come with VC Express. by the way). MFC is old, and not very elegant, and has
quite a learning curve. But there is a huge base of available code samples for
it, and Microsoft is once again working on improving it (after many years of
neglect). MFC is not portable to other platforms, but if you separate the
back-end of your application from the GUI, you can port the back-end to other
platforms such as MAC/linux. For me, one of the advantages of going the MFC
route is that you can use static linking, which means that you can deploy
without installing any components on the target machine.
[Note that the main newsgroups for standard C++ are microsoft.public.vc.language
and microsoft.public.vc.mfc]
If you use C#, you will use the .NET library, which is more elegant, and
probably easier to learn than MFC. If you go this route, you need to make sure
that the appropriate version of the .NET framework is installed on the target
system.
There are also hybrid methods, where you write your back-end in standard C++,
the GUI in C#, and build an interface layer using C++/CLI. This may be
appropriate if you have a large amount of legacy C++ code, but it means you have
to learn and understand three languages.
Feel free to ask more questions. This is an important decision, and you should
be sure you make the one that is correct for you.
--
David Wilkinson
Visual C++ MVP
date: Fri, 18 Jul 2008 08:54:23 -0400
author: David Wilkinson
Re: learn C++ or C#
Ken Foskey wrote:
> On Fri, 18 Jul 2008 11:46:56 +0200, Giovanni Dicanio wrote:
>
>
>> I've heard about Mono before. But I wonder: what is the level of
>> implementation of Mono?
>> Is Mono as robust as the Microsoft .NET framework implementation?
>
> A lot of the .net framework is directly from Microsoft. A lot is
> implemented a totally different way. I expect that it will be very
> compliant as time progresses just not now.
>
>> Does Mono fully support C# 3?
>
> I cannot compile anymore:
>
> [Task:File=/home/ken/projects/Capture/Capture/inMatch.cs, Line=266,
> Column=32, Type=Error, Priority=Normal, Description=Feature `query
> expressions' cannot be used because it is not part of the C# 2.0
> language specification(CS1644)]
Sounds like a command line option, or lack thereof, put you in C# 2
compatibility mode. Certainly the compiler wouldn't be describing a feature
such as LINQ query expressions if it didn't understand it.
>
>> Does Mono fully support .NET Framework 3.5 ?
>
> definitely not.
>
> Mono is about portability you have to build with that in mind and you
> can be fully portable. I write my test classes on Console and run
> them on Linux as well. I have socket based tests and I need two
> machine to make it work.
>
> Ken
date: Fri, 18 Jul 2008 08:56:22 -0500
author: Ben Voigt [C++ MVP] am
Re: learn C++ or C#
> Assuming that you want to write GUI applications for Windows, you
> need a library.
> If you use native C++, you will probably want to use the MFC library
> (which does not come with VC Express. by the way). MFC is old, and
> not very elegant, and has quite a learning curve. But there is a huge
ATL/WTL follow modern C++ principles much better than MFC, and should
probably be the library of choice for C++ Windows-only GUI.
> base of available code samples for it, and Microsoft is once again
> working on improving it (after many years of neglect). MFC is not
> portable to other platforms, but if you separate the back-end of your
> application from the GUI, you can port the back-end to other
> platforms such as MAC/linux. For me, one of the advantages of going
> the MFC route is that you can use static linking, which means that
> you can deploy without installing any components on the target
> machine.
> [Note that the main newsgroups for standard C++ are
> microsoft.public.vc.language and microsoft.public.vc.mfc]
>
> If you use C#, you will use the .NET library, which is more elegant,
> and probably easier to learn than MFC. If you go this route, you need
> to make sure that the appropriate version of the .NET framework is
> installed on the target system.
>
> There are also hybrid methods, where you write your back-end in
> standard C++, the GUI in C#, and build an interface layer using
> C++/CLI. This may be appropriate if you have a large amount of legacy
> C++ code, but it means you have to learn and understand three
> languages.
> Feel free to ask more questions. This is an important decision, and
> you should be sure you make the one that is correct for you.
date: Fri, 18 Jul 2008 08:58:04 -0500
author: Ben Voigt [C++ MVP] am
Re: learn C++ or C#
On Jul 18, 2:56 pm, "Ben Voigt [C MVP]" <r...@nospam.nospam> wrote:
> > [Task:File=/home/ken/projects/Capture/Capture/inMatch.cs, Line=266,
> > Column=32, Type=Error, Priority=Normal, Description=Feature `query
> > expressions' cannot be used because it is not part of the C# 2.0
> > language specification(CS1644)]
>
> Sounds like a command line option, or lack thereof, put you in C# 2
> compatibility mode. Certainly the compiler wouldn't be describing a feature
> such as LINQ query expressions if it didn't understand it.
Indeed, you need the command line option -langversion:linq but to
quote the documentation:
<quote>
This enables the C# 3.0 support. Only a few features of C# 3.0 have
been implemented in the Mono C# compiler, so not everything is
available.
</quote>
:(
Jon
date: Fri, 18 Jul 2008 07:08:13 -0700 (PDT)
author: Jon Skeet [C# MVP]
Re: learn C++ or C#
ok. Thanks.
"Giovanni Dicanio" <gdicanio@_NOSPAM_email_DOT_it> wrote in message
news:uyIJu8K6IHA.1592@TK2MSFTNGP04.phx.gbl...
>
> "Arne Vajhøj" ha scritto nel messaggio
> news:487fdc67$0$90274$14726298@news.sunsite.dk...
>
>> First I will make a prediction: the .vc guys will suggest C++ and
>> the .csharp guys will suggest C#.
>>
>> :-)
>
> I'm a .vc guy :-)
>
>
>> If you want to write general business apps, then I will suggest C#.
>
> I agree with that.
>
>
>> If you have special requirements for real time, embedded, device
>> driver programming and similar then go for C++.
>
> Moreover, if you want to build Windows shell extensions, you should use
> C++.
>
> If you want crossplatform code, you should use C++ (with proper libraries
> like wxWidgets for the GUI).
>
> If you want to build small .exe's easy to deploy (no need of huge runtime
> to distribute), you should use C++ (with CRT/MFC/ATL statically linked).
>
> If you learn C++ first, then moving to C# is a very easy path, as others
> wisely wrote.
> Instead, the opposite is not true.
>
> Both languages have pro's and con's: choose the better tool for your
> particular job.
>
> Giovanni
>
>
>
date: Fri, 18 Jul 2008 11:46:21 -0500
author: Daniel
Re: learn C++ or C#
Thanks.
"David Wilkinson" wrote in message
news:eeyAnVN6IHA.4352@TK2MSFTNGP03.phx.gbl...
> Daniel wrote:
>> If I haven't made substantial investment in either C++ or C#, which
>> language would the experts recommend I become well acquainted with?
>
> Daniel:
>
> As you are posting in dotnet groups, you should know that there are
> actually three languages
>
> C++
> C#
> C++/CLI
>
> Up to now you have been using C++/CLI, which is the wrong choice if you
> want to write GUI Windows applications, because Microsoft no longer
> recommends C++/CLi for writing GUI .NET applications.
>
> Assuming that you want to write GUI applications for Windows, you need a
> library.
>
> If you use native C++, you will probably want to use the MFC library
> (which does not come with VC Express. by the way). MFC is old, and not
> very elegant, and has quite a learning curve. But there is a huge base of
> available code samples for it, and Microsoft is once again working on
> improving it (after many years of neglect). MFC is not portable to other
> platforms, but if you separate the back-end of your application from the
> GUI, you can port the back-end to other platforms such as MAC/linux. For
> me, one of the advantages of going the MFC route is that you can use
> static linking, which means that you can deploy without installing any
> components on the target machine.
>
> [Note that the main newsgroups for standard C++ are
> microsoft.public.vc.language and microsoft.public.vc.mfc]
>
> If you use C#, you will use the .NET library, which is more elegant, and
> probably easier to learn than MFC. If you go this route, you need to make
> sure that the appropriate version of the .NET framework is installed on
> the target system.
>
> There are also hybrid methods, where you write your back-end in standard
> C++, the GUI in C#, and build an interface layer using C++/CLI. This may
> be appropriate if you have a large amount of legacy C++ code, but it means
> you have to learn and understand three languages.
>
> Feel free to ask more questions. This is an important decision, and you
> should be sure you make the one that is correct for you.
>
> --
> David Wilkinson
> Visual C++ MVP
date: Fri, 18 Jul 2008 11:58:12 -0500
author: Daniel
Re: learn C++ or C#
On Jul 18, 1:36 pm, Daniel James wrote:
> A good implementation plan is to write your back-end code -- the
> business logic of your application -- in a fast portable language (such
> as C) so that it can be built to run on the maximum possible number of
> platforms, and then to write a GUI wrapper around it for each platform
> on which you want to ship ... you might choose to write such a GUI
> wrapper in C# for a Windows version of your software, though other
> possibilities (including VB, Java, Python, etc) exist.
I disagree about the "business logic in C" part. In practice,
standard C tends to be too low-level, verbose, and overcomplicated
for many common patterns that arise when developing a typical business
layer in many desktop and LOB applications. I'd still recommend C# for
that.
Leave C for tightly optimized algorithm implementations, device
drivers, shell plugins, MSI custom actions, etc.
date: Fri, 18 Jul 2008 10:52:09 -0700 (PDT)
author: Pavel Minaev
Re: learn C++ or C#
On Jul 18, 1:52 pm, Pavel Minaev wrote:
> On Jul 18, 1:36 pm, Daniel James wrote:
>
> > A good implementation plan is to write your back-end code -- the
> > business logic of your application -- in a fast portable language (such
> > as C) so that it can be built to run on the maximum possible number of
> > platforms, and then to write a GUI wrapper around it for each platform
> > on which you want to ship ... you might choose to write such a GUI
> > wrapper in C# for a Windows version of your software, though other
> > possibilities (including VB, Java, Python, etc) exist.
>
> I disagree about the "business logic in C" part. In practice,
> standard C tends to be too low-level, verbose, and overcomplicated
> for many common patterns that arise when developing a typical business
> layer in many desktop and LOB applications. I'd still recommend C# for
> that.
>
> Leave C for tightly optimized algorithm implementations, device
> drivers, shell plugins, MSI custom actions, etc.
On the low level stuff. What exactly is the "lowest" level in Windows
C. I don't mean assembly or machine language. I mean if I wanted
to know how graphics are really drawn on the screen. What would I
look at? I know I can use C to createwindow or something like it,
but how is it doing it? Is that part in C or C? Is that the hidden
source code that Microsoft uses?
Thanks.
date: Fri, 18 Jul 2008 11:00:29 -0700 (PDT)
author: jmDesktop
Re: learn C++ or C#
On Fri, 18 Jul 2008 11:00:29 -0700, jmDesktop
wrote:
> On the low level stuff. What exactly is the "lowest" level in Windows
> C++.
First, let's straighten out some terminology: I don't feel that there's
any such thing as "Windows C++". C++ is a language, Windows is an
operating system with an API (or, a lot of different APIs, depending on
how you look at it :) ).
The majority of the Windows API has nothing at all to do with C++. It's
all accessible by C or other similar purely procedural, non-OOP
languages. Even where the Windows API starts to look like C++ (e.g. COM,
GDI+), you can in fact get by without C++ albeit with more complicated
code (since you have to write explicitly the things that C++ would do for
you).
So it's important to be clear about whether you're talking about the
Windows API and if so what part, or if you're talking about a language and
if so, why it is a particular language is of particular interest.
> I don't mean assembly or machine language. I mean if I wanted
> to know how graphics are really drawn on the screen. What would I
> look at?
That's a pretty vague question. The most literal answer is "the graphics
driver". That's the part of the operation system that actually interfaces
directly with the video hardware, and it's the only thing that really
knows "how graphics are really drawn on the screen".
> I know I can use C++ to createwindow or something like it,
CreateWindow() doesn't draw graphics. It just sets up an OS object that
provides for a specific kind of way to draw graphics.
> but how is it doing it?
How is what doing what? That's a lot of pronouns without any clear
antecedent.
Pete
date: Fri, 18 Jul 2008 11:20:33 -0700
author: Peter Duniho
Re: learn C++ or C#
Ben Voigt [C++ MVP] wrote:
> I guess I didn't actually say "for new C++ code". I meant to though. There
> are certainly good reasons to keep an existing MFC application as MFC that
> probably outweigh any benefits of WTL.
No, I'm certainly not going to rewrite my existing MFC applications. But even if
I were to start a new GUI application, I would probably go with MFC because I
know what to do, and have a bunch of supporting code ready to go, etc.
To use WTL or C#/.NET I would have to learn a bunch of stuff, and of the two I
think I would go with C#.
Fortunately most of my consulting work is cross-platform non-GUI C++, si I do
not need to worry about this. The code is developed in Visual Studio, but runs
as a console application in various linux/Unix systems, as well as Windows. My
client also wraps it in C++/CLI for Windows GUI with C#, but I am not
responsible for that.
--
David Wilkinson
Visual C++ MVP
date: Fri, 18 Jul 2008 15:00:34 -0400
author: David Wilkinson
Re: learn C++ or C#
On Jul 18, 2:20 pm, "Peter Duniho"
wrote:
> On Fri, 18 Jul 2008 11:00:29 -0700, jmDesktop
> wrote:
>
> > On the low level stuff. What exactly is the "lowest" level in Windows
> > C.
>
> First, let's straighten out some terminology: I don't feel that there's
> any such thing as "Windows C". C is a language, Windows is an
> operating system with an API (or, a lot of different APIs, depending on
> how you look at it :) ).
>
> The majority of the Windows API has nothing at all to do with C. It's
> all accessible by C or other similar purely procedural, non-OOP
> languages. Even where the Windows API starts to look like C (e.g. COM,
> GDI), you can in fact get by without C albeit with more complicated
> code (since you have to write explicitly the things that C would do for
> you).
>
> So it's important to be clear about whether you're talking about the
> Windows API and if so what part, or if you're talking about a language and
> if so, why it is a particular language is of particular interest.
>
> > I don't mean assembly or machine language. I mean if I wanted
> > to know how graphics are really drawn on the screen. What would I
> > look at?
>
> That's a pretty vague question. The most literal answer is "the graphics
> driver". That's the part of the operation system that actually interfaces
> directly with the video hardware, and it's the only thing that really
> knows "how graphics are really drawn on the screen".
>
> > I know I can use C to createwindow or something like it,
>
> CreateWindow() doesn't draw graphics. It just sets up an OS object that
> provides for a specific kind of way to draw graphics.
>
> > but how is it doing it?
>
> How is what doing what? That's a lot of pronouns without any clear
> antecedent.
>
> Pete
How is a windows drawn on the screen? Is that where the OS provided
APIs come in (we don't need to know how they work)?
date: Fri, 18 Jul 2008 11:59:48 -0700 (PDT)
author: jmDesktop
Re: learn C++ or C#
On Fri, 18 Jul 2008 11:59:48 -0700, jmDesktop
wrote:
> How is a windows drawn on the screen? Is that where the OS provided
> APIs come in (we don't need to know how they work)?
Again, it depends. The question is too vague to answer, because there are
a variety of ways a window could be drawn on the screen.
That said, for the typical, mainstream Windows application, yes...the OS
itself provides the implementation that actually draws the window-specific
graphics on the screen. This includes things like the frame, titlebar,
menu, scrollbars, etc.
An application uses this built-in functionality, and then optionally
provides its own customized drawing for the "client" area of the window.
Where it doesn't provide customized drawing, it usually simply adds "child
windows" (in a .NET Forms application, this is in the form of Control
sub-classes) to the main window, and each child window implements its own
drawing (again, as part of the OS API and implementation).
Pete
date: Fri, 18 Jul 2008 12:26:21 -0700
author: Peter Duniho
Re: learn C++ or C#
Actually, VB.NET usage has surpassed C#. Thought I would point that out,
this came from a forester survey if memory serves me correctly.
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
-------------------------------------------------------
"Larry Smith" wrote in message
news:#qvvjVH6IHA.3512@TK2MSFTNGP02.phx.gbl...
>> I meant which of the two languages C++ or C# should I pursue, if I don't
>> already have projects I have to support in either one. If I I have to
>> give support for an application I created in one of those two languages,
>> then that is the language I have to be most familiar with. Once I use
>> the language in a substantial project I have to support, I am committed
>> to that language.
>
> This is a religious issue and it really depends on what you plan on doing.
> That said, for "general-purpose" programming in the Windows world, C# is
> usually the way to go these days IMO. I believe the trend has been
> strongly moving in that direction for a period of years now. Note (FWIW)
> that I spent many years in the C++ trenches.
>
date: Fri, 18 Jul 2008 20:47:06 -0400
author: Alvin Bruney [ASP.NET MVP] vapor dan using hot male spam filter
Re: learn C++ or C#
In article news:, David Wilkinson
wrote:
> C++/CLI ... is the wrong choice if you want to write GUI Windows
> applications, because Microsoft no longer recommends C++/CLi
> for writing GUI .NET applications.
If you are an experienced C++ programmer but know no C# (or other .NET
language) and you want to write an application for the .NET runtime that
has some GUI functionality but a lot more back-end logic it might well
be ideal to use C++/CLI for the whole thing. There are no hard-and-fast
rules, here, just a lot of technologies that can play together or on
their own and which have different strengths and weaknesses.
It's perfectly possibly to use C++/CLI to write GUI .NET applications --
it wouldn't be everybody's choice (for a number of good reasons) but it
is certainly possible ... and what Microsoft "recommend" shouldn't play
a big part in your decision-making process. Their recommendations are
often more political than technical, and in any case can't consider the
specific technical factors affecting any individual case.
For that matter: I don't think I've seen any definitive statement from
Microsoft saying that C++/CLI is no longer recommended for GUI .NET
applications ... can you provide a reference/link for that?
> If you use native C++, you will probably want to use the MFC library
> ...
That's certainly a valid choice, and a reasonable one for a native C++
application that's limited to the Windows platform.
Other good choices would be Qt or the wxWdigets libraries which also
target other OSes, such as linux and MacOS.
> There are also hybrid methods, where you write your back-end in
> standard C++, the GUI in C#, and build an interface layer using
> C++/CLI. This may be appropriate if you have a large amount of
> legacy C++ code ...
Yes, indeed. It's also an appropriate strategy if you want your back-end
code to be portable to ther systems but want to code a platform-specific
GUI for each target system to take best advantage of the facilities of
each platform. The Windows front-end can then be C# (or whatever takes
your fancy), and you can use other tools for other platforms.
Cheers,
Daniel.
date: Sat, 19 Jul 2008 12:02:55 +0100
author: Daniel James
Re: learn C++ or C#
Daniel James wrote:
> In article news:, David Wilkinson
> wrote:
>> C++/CLI ... is the wrong choice if you want to write GUI Windows
>> applications, because Microsoft no longer recommends C++/CLi
>> for writing GUI .NET applications.
>
> If you are an experienced C++ programmer but know no C# (or other .NET
> language) and you want to write an application for the .NET runtime that
> has some GUI functionality but a lot more back-end logic it might well
> be ideal to use C++/CLI for the whole thing. There are no hard-and-fast
> rules, here, just a lot of technologies that can play together or on
> their own and which have different strengths and weaknesses.
>
> It's perfectly possibly to use C++/CLI to write GUI .NET applications --
> it wouldn't be everybody's choice (for a number of good reasons) but it
> is certainly possible ... and what Microsoft "recommend" shouldn't play
> a big part in your decision-making process. Their recommendations are
> often more political than technical, and in any case can't consider the
> specific technical factors affecting any individual case.
>
> For that matter: I don't think I've seen any definitive statement from
> Microsoft saying that C++/CLI is no longer recommended for GUI .NET
> applications ... can you provide a reference/link for that?
>
>> If you use native C++, you will probably want to use the MFC library
>> ...
>
> That's certainly a valid choice, and a reasonable one for a native C++
> application that's limited to the Windows platform.
>
> Other good choices would be Qt or the wxWdigets libraries which also
> target other OSes, such as linux and MacOS.
>
>> There are also hybrid methods, where you write your back-end in
>> standard C++, the GUI in C#, and build an interface layer using
>> C++/CLI. This may be appropriate if you have a large amount of
>> legacy C++ code ...
>
> Yes, indeed. It's also an appropriate strategy if you want your back-end
> code to be portable to ther systems but want to code a platform-specific
> GUI for each target system to take best advantage of the facilities of
> each platform. The Windows front-end can then be C# (or whatever takes
> your fancy), and you can use other tools for other platforms.
Daniel:
These are indeed difficult decisions, and I do not believe the dust has fully
settled on the managed/native issue (maybe it never will).
I for one am glad that I have stuck with native code and MFC up till now.
Investing a lot of time in MC++ would certainly have been a big mistake, and
it's beginning to look like the same for C++/CLI (at least for GUI).
QT or wxwidgets are good for cross-platform, but QT is expensive and I'm not
sure about the longevity of wxwidgets. But really I do not think about porting
my applications any more, because I feel that CrossOver MAC and CrossOver Linux
do a pretty good job of running Windows applications.
So although I started out separating the "business logic" of my application from
the GUI (and writing the former in just ANSI C++, with no Microsoft-specific
stuff), I now think of using it in a revised app with the GUI in .NET and C#.
But not any time soon.
It's a pity that Microsoft's only supported native C++ GUI platform is MFC, but
there it is. It's inelegant, and bloated, but it works, for the most part. So
for now I'm sticking with MFC, forgetting about C++/CLI, and starting to learn
C# in my spare time.
--
David Wilkinson
Visual C++ MVP
date: Sat, 19 Jul 2008 09:56:20 -0400
author: David Wilkinson
Re: learn C++ or C#
On Jul 19, 4:36 pm, "Giovanni Dicanio" <gdicanio@_NOSPAM_email_DOT_it>
wrote:
> The main problem of C code is "old style" C code, more similar to C than
> C.
> e.g. when raw pointers like char* are used instead of robust string classes
> like std::string/CString, or instead of robust container classes like
> std::vector.
>
> Using tools like string classes, container classes and smart pointers makes
> C code robust and easy to write and manage.
Well, sort of. Until you accidentially invalidate an iterator by
modifying the container - U.B. Or mix signed and unsigned integer
types in an arithmetic expression and get weird results because of the
silent signed->unsigned conversion rule (and it is very easy to do so,
since a lot of standard library functions return unsigned integers -
e.g. size() of any STL container is unsigned). Or forget that
assignment operator and "copy" constructor for auto_ptr are actually
move and not copy. Or put an auto_ptr into a container (and why not,
if it lets you do so without any compaints...). Or try to make sense
of three paragraphs of ISO C standard describing overload resolution
for template functions in presence of partial specializations (the one
where synthetic types are involved). The problem is, you have to be a C
expert to write good C code, and, not any less important, to be
able to understand advanced C code written by others that's thrown
at you.
Don't get me wrong, C is a great language, and the time I've spent
writing in it was great. But from my experience, I would never let it
anywhere near domain logic except where it is spefically needed, when
I have the choice, because too many times I've witnessed how even
skilled and experienced (5 years) C developers wrote some seemingy
trivial code which then broke things in subtle ways. I once spent 2
whole work days in the debugger trying to find the code that lead to
"Heap corrupted" error which invariably manifested itself under
unclear conditions after the program was used for 2-3 hours. It's not
fun at all. It's also something that's much, much rarer in the
"managed code" land.
date: Sat, 19 Jul 2008 09:40:57 -0700 (PDT)
author: Pavel Minaev
Re: learn C++ or C#
In article news:<#eYqo1Z6IHA.1200@TK2MSFTNGP04.phx.gbl>, Giovanni Dicanio wrote:
> > For that matter: I don't think I've seen any definitive statement
> > from Microsoft saying that C++/CLI is no longer recommended for
> > GUI .NET applications ... can you provide a reference/link for
> > that?
>
> I would suggest reading this comment by Steve Teixeira to Somasegar's
> blog post titled "Visual C++ Futures":
>
> http://blogs.msdn.com/somasegar/archive/2007/08/08/visual-c-futures.aspx#4746812
Thanks for that. I had seen it before ... and I don't see anything there
that suggests that C++/CLI is "not recommended" for GUI code. All Steve
says that's at all relevant is that MS don't propose to spend time writing
GUI design tools that target C++/CLI when they already have some that
target C# and there are other things they want to spend resources on to
support C++.
That's a fair enough viewpoint, and the message in the blog is that MS (or,
at least, the C++ team) are following what they believe to be the wishes of
their customers in that respect.
That doesn't mean that they don't recommend using C++/CLI, it means that
they won't provide any tools to help you do that. That's not big deal,
really, because it doesn't actually matter what language any automatically
generated code is in -- the form designer might as well spit out a compiled
assembly as C#. Microsoft do say that the C# generated by the designers
isn't supposed to be edited by the user -- that's how they get away with
emitting such poorly structured code.
You don't actually *need* to have any tools to help you write GUI code,
anyway. You can do it all by hand. The form designers may save you some
time but in a large project that time is not significant, and hand-crafted
code will be better structured and more maintainable than anything that
comes from the designers.
Cheers,
Daniel.
date: Sun, 20 Jul 2008 11:16:36 +0100
author: Daniel James
Re: learn C++ or C#
Daniel James wrote:
> Thanks for that. I had seen it before ... and I don't see anything there
> that suggests that C++/CLI is "not recommended" for GUI code. All Steve
> says that's at all relevant is that MS don't propose to spend time writing
> GUI design tools that target C++/CLI when they already have some that
> target C# and there are other things they want to spend resources on to
> support C++.
>
> That's a fair enough viewpoint, and the message in the blog is that MS (or,
> at least, the C++ team) are following what they believe to be the wishes of
> their customers in that respect.
>
> That doesn't mean that they don't recommend using C++/CLI, it means that
> they won't provide any tools to help you do that. That's not big deal,
> really, because it doesn't actually matter what language any automatically
> generated code is in -- the form designer might as well spit out a compiled
> assembly as C#. Microsoft do say that the C# generated by the designers
> isn't supposed to be edited by the user -- that's how they get away with
> emitting such poorly structured code.
>
> You don't actually *need* to have any tools to help you write GUI code,
> anyway. You can do it all by hand. The form designers may save you some
> time but in a large project that time is not significant, and hand-crafted
> code will be better structured and more maintainable than anything that
> comes from the designers.
Daniel:
Maybe I should not say "Microsoft does not recommend" then. Do you think
"Microsoft does not promote" would be more accurate? Or do you feel that is too
strong also?
I'm sure there are some advanced users who use C++/CLI to write GUI .NET
applications, but the vast majority of the C++/CLI questions I see in the
newsgroups/forums come from novices who have downloaded VC++ Express and have
found that, absent MFC, the only out-of-the-box way to write GUI applications is
to use .NET. Many of these folks, like the OP, are not even aware that the
language they are using is not C++. They have chosen C++ because the name sounds
familiar, or perhaps know it a bit already, but the vast majority of these
people would have been batter off downloading VC# Express instead. At any rate,
they are not going to be happy if the forms designer in VC++ is crippled.
But even experienced C++ users seem to be embracing C# over C++/CLI. It's not
just the designer tools; some features (such as LINQ) are not even available in
C++/CLI. It's a shame after all the effort that went into C++/CLI (after the
initial MC++ debacle), but there it is.
What's the solution? I think MS has to fully face up to the fact that VC++ is
for native code, get the IDE back to the level of usability/responsiveness we
had in VC6, and put MFC (and the PSDK) into VC++ Express. I don't think it is
anybody's interest to "entrap" beginners into C++/CLI.
--
David Wilkinson
Visual C++ MVP
date: Sun, 20 Jul 2008 07:05:32 -0400
author: David Wilkinson
Re: learn C++ or C#
Pavel Minaev wrote:
> On Jul 19, 4:36 pm, "Giovanni Dicanio" <gdicanio@_NOSPAM_email_DOT_it>
> wrote:
> [...]
>> Using tools like string classes, container classes and smart pointers makes
>> C++ code robust and easy to write and manage.
>
> Well, sort of. Until you accidentially invalidate an iterator by
> modifying the container - U.B. Or mix signed and unsigned integer
> types in an arithmetic expression and get weird results because of the
> silent signed->unsigned conversion rule (and it is very easy to do so,
> since a lot of standard library functions return unsigned integers -
> e.g. size() of any STL container is unsigned). Or forget that
> assignment operator and "copy" constructor for auto_ptr are actually
> move and not copy. Or put an auto_ptr into a container (and why not,
> if it lets you do so without any compaints...). Or try to make sense
> of three paragraphs of ISO C++ standard describing overload resolution
> for template functions in presence of partial specializations (the one
> where synthetic types are involved). The problem is, you have to be a C
> ++ expert to write good C++ code, and, not any less important, to be
> able to understand advanced C++ code written by others that's thrown
> at you.
I've looked at this list and I agree with the unsigned vs. signed
issue, everything else I don't agree with. I can't see how you can
implement a dynamic array that doesn't invalidate iterators upon
insertion (might be my limited imagination, though).
I don't think I've used 'std::auto_ptr' in the last five years. If
I needed a smart pointer (which is rather rare if you use the above
mentioned tools) I needed (and used) a ref-counting off-the-shelf
one. And there's no function template partial specialization, so it
can't mess with the overloading rules.
I agree that C++ is a huge and complex beast to deal with, but I
also agree with Giovanni that a modern use of it leads to save,
robust, and easily maintainable code. Unfortunately I also have to
agree that too few programmers are using it that way.
I think it all boils down to the old observation that C's heritage
is both a bless and a curse for C++. That's valid for teaching it,
too. C++ was taught as a better C for far too long and that still
hasn't changed enough. To many studentsare taught a style that begs
for subtle bugs, alltough there are better ways to make use of the
language.
My personal opinion is that most programmers would benefit a lot
from reading Koenig/Moo's "Accelerated C++" even though it's meant to
be for novices. I read it many years ago (because I teach C++) and
while I don't think it showed me anything I didn't know yet, it did
teach me that C++ has changed enough throughout the last 15 years to
make it possible to teach it to students in a way that makes them
programming the style Giovanni advertized from day one.
I have 15-20 lectures (90mins each) to teach C++ to students who had
one year of Java-only exposure and found that it's possible to go all
the way from "Hello, world!" to template meta-programming in that
time. I hammer a lot of rules of thumb into them and teach them a
style where C++ is a like big box of Lego bricks from which your can
safely build anything you need. I rarely ever have a semester where I
give an exercise where they have to write 'new', let alone 'delete',
but they see 'std::vector' in lesson two, along with 'std::string'
and IO. C++ is still more unsafe than other languages because it just
relies on programmers not to do stupid things, but given a modern
combination of compiler/RTL/std lib you get a lot of meaningful run-
time error messages in debug mode while still enjoying full speed in
release mode.
> Don't get me wrong, C++ is a great language, and the time I've spent
> writing in it was great. But from my experience, I would never let it
> anywhere near domain logic except where it is spefically needed, when
> I have the choice, because too many times I've witnessed how even
> skilled and experienced (5+ years) C++ developers wrote some seemingy
> trivial code which then broke things in subtle ways.
But that's really hard to do if you don't do manual memory and the
like. Mostly this happens because programmers only use C++ as a
better C -- which is exactly what Giovanni said would lead to subtle
bugs.
> I once spent 2
> whole work days in the debugger trying to find the code that lead to
> "Heap corrupted" error which invariably manifested itself under
> unclear conditions after the program was used for 2-3 hours. It's not
> fun at all. It's also something that's much, much rarer in the
> "managed code" land.
IME the crashs reported from testing tend to happen in certain parts
|