Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 11-02-2011, 09:01 PM   #1
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,613
Default C# versus C++

I found this funny and quite eloquent. In this MSDN walkthrough article there are alternative samples in different COM-aware languages. This is one of them in C#:

Code:
using System;
using SideBySideLib;

class Example
{
   static void Main()
   {
      var obj = new SideBySideClassClass();
      Console.WriteLine(obj.Version());
      Console.ReadLine();
   }
}
To do the same in C++ you have to (and thank God you have Visual Studio):

Quote:
Create a new Visual C++ Win32 Console Project called client in a sibling folder relative to the SideBySide project's folder. In the Win32 Application Wizard, on the Application Settings tab, check the Add support for ATL check box.

Edit stdafx.h and add the following line at the top of the file, immediately after the #pragma once:
Code:
#define _WIN32_DCOM
Also in stdafx.h add the following line at the bottom of the file:
Code:
#import "..\deployed\SideBySide.dll" no_namespace
Replace the contents of client.cpp with this code:
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;

void ErrorDescription(HRESULT hr)
{
    TCHAR* szErrMsg;
    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
      FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 
      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
      (LPTSTR)&szErrMsg, 0, NULL) != 0)
   {
        cout << szErrMsg << endl;
        LocalFree(szErrMsg);
    }
   else
        cout << "Could not find a description for error 0x" 
          << hex << hr << dec << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
   CoInitializeEx(0, COINIT_MULTITHREADED);

   {
      ISideBySideClassPtr ptr;
      HRESULT hr = ptr.CreateInstance(__uuidof(SideBySideClass));
      if (SUCCEEDED(hr))
      {
         cout << ptr->Version() << endl;
      }
      ErrorDescription(hr);

      char c;
      cin >> c;
   }

   CoUninitialize();

   return 0;
}
Wow.
__________________
Life starts every day anew. Prospects not so good...
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 12-02-2011, 08:25 PM   #2
Acero
Newbie
 
Acero's Avatar

 
Join Date: May 2009
Location: Olean, United States
Posts: 20
Default

C# is great and so much more time efficient. But I'll always have a special place in my heart for C++, there is something that just looks so elegant about how complicated it is.

Quote:
Originally Posted by Japo View Post
I found this funny and quite eloquent. In this MSDN walkthrough article there are alternative samples in different COM-aware languages. This is one of them in C#:

Code:
using System;
using SideBySideLib;

class Example
{
   static void Main()
   {
      var obj = new SideBySideClassClass();
      Console.WriteLine(obj.Version());
      Console.ReadLine();
   }
}
To do the same in C++ you have to (and thank God you have Visual Studio):



Wow.
Acero is offline                         Send a private message to Acero
Reply With Quote
Old 13-02-2011, 02:07 AM   #3
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,613
Default

I like C, and it was my first language (well second after QBasic really), but I never really got to learn and use the C++ superset. For a systems programming language with modern features, I think it would be much better if C++ were replaced with D (not gonna happen):

http://www.digitalmars.com/d/
__________________
Life starts every day anew. Prospects not so good...
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 17-02-2011, 11:31 PM   #4
KrazeeXXL
BORG

 
Join Date: Feb 2009
Location: Dog City, Cayman Islands
Posts: 107
Default

I hate 'em both.

BASIC FTW!
KrazeeXXL is offline                         Send a private message to KrazeeXXL
Reply With Quote
Old 19-02-2011, 04:55 PM   #5
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,613
Default

Aw man I hate Basic syntax. Dim, Call, Sub, Function, line breaks...? Eew. :P
__________________
Life starts every day anew. Prospects not so good...
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 20-02-2011, 05:30 PM   #6
_r.u.s.s.
I'm not Russ
but an ex-alektorophobic
 
_r.u.s.s.'s Avatar


 
Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
Default

does basic even support objects?
__________________
_r.u.s.s. is offline                         Send a private message to _r.u.s.s.
Reply With Quote
Old 20-02-2011, 10:38 PM   #7
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,613
Default

Well there are thousands of different little-known languages in the Basic family alive today, they only have the keywords in common.

As for (Microsoft) Visual Basic .NET, it supports objects as per the .NET Framework just like C#, actually in principle you can do with it whatever you can do with C# (except some fringe features), you can really translate between the two line by line most of the time, and MSDN always has samples for both C# and VB on each page. But it was C# that was designed as the main .NET language, VB.NET was made afterwards as a way to accommodate programmers of previous versions of VB into the new platform.

As for Microsoft Visual Basic 6.0, it did support objects partially, but without inheritance, only one default constructor that couldn't have any paramters... But most VB programmers never created their own objects besides GUI Forms, unless they needed to author a COM/ActiveX component. And because of the Basic philosophy of "making things easier" for beginners, Forms aren't treated like classes even though they're derived classes under the hood, and an instance is created automatically with the name of the class, so when VB programmers move to .NET they don't even understand the difference between a class and an instance of it.

Basic should be killed with fire. :P
__________________
Life starts every day anew. Prospects not so good...
Japo is offline                         Send a private message to Japo
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
VERSUS articles red_avatar Abandoned Times 11 21-04-2009 02:55 AM
Swiss Versus Sean swiss Music, Art, Movies 107 28-08-2006 07:09 PM
Magic Versus Swiss - Round 2 swiss Music, Art, Movies 125 16-11-2005 12:56 PM
Magic Versus Swiss - Round 2 swiss Music, Art, Movies 46 09-11-2005 07:11 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 12:19 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.