Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualHodgman

Posted 11 December 2012 - 05:51 PM

You could argue that the separation between declaration and implementation is built into the language in C# and java using interfaces, as opposed to C++s frankly demented compilation model.

Yeah the real issue to me isn't the .h/.cpp schism, but the actual way in which C++ code is compiled. #include just means copy&paste, whereas in other languages, including a module is a higher level construct. I've often seen CPP files that are 60k lines long, after all the #includes have been resolved... (hence crap like WIN32_LEAN_AND_MEAN being invented). No matter what kind of .h/.cpp organisation you use, you can't fix the compilation model (nor the fact that so much of the ABI is implementation defined, which keeps C around for interop).

If you do want to write more C# style code in C++ though, I've worked on a code base that looked like:
//foo.h
#pragma once
class IFoo
{
public:
  static IFoo* New();
  virtual ~IFoo() {}
  virtual void Frobnicate() = 0;
};

//foo.cpp
class Foo : public IFoo
{
  int member;
  void Frobnicate()
  {
	member = 42;
	printf("hello world");
  }
};
IFoo* IFoo::New() { return new Foo; }
p.s. it's not my cup of tea though.

#2Hodgman

Posted 11 December 2012 - 05:51 PM

You could argue that the separation between declaration and implementation is built into the language in C# and java using interfaces, as opposed to C++s frankly demented compilation model.

Yeah the real issue to me isn't the .h/.cpp schism, but the actual way in which C++ code is compiled. #include just means copy&paste, whereas in other languages, including a module is a higher level construct. I've often seen CPP files that are 60k lines long, after all the #includes have been resolved... (hence crap like WIN32_LEAN_AND_MEAN being invented). No matter what kind of .h/.cpp organisation you use, you can't fix the compilation model (nor the fact that so much of the ABI is implementation defined, which keeps C around for interop).

If you do want to write more C# style code in C++ though, I've worked on a code base that looked like:
//foo.h
#pragma once

class IFoo
{
public:
  static IFoo* New();
  virtual ~IFoo() {}
  virtual void Frobnicate() = 0;
};

//foo.cpp
class Foo : public IFoo
{
  int member;
  void Frobnicate()
  {
	member = 42;
	printf("hello world");
  }
};
IFoo* IFoo::New() { return new Foo; }
p.s. it's not my cup of tea though.

#1Hodgman

Posted 11 December 2012 - 05:49 PM

You could argue that the separation between declaration and implementation is built into the language in C# and java using interfaces, as opposed to C++s frankly demented compilation model.

Yeah the real issue to me isn't the .h/.cpp schism, but the actual way in which C++ code is compiled. #include just means copy&paste, whereas in other languages, including a module is a higher level construct. I've often seen CPP files that are 60k lines long, after all the #includes have been resolved... (hence crap like WIN32_LEAN_AND_MEAN being invented). No matter what kind of .h/.cpp organisation you use, you can't fix the compilation model.

If you do want to write more C# style code in C++ though, I've worked on a code base that looked like:
//foo.h
#pragma once

class IFoo
{
public:
  static IFoo* New();
  virtual ~IFoo() {}
  virtual void Frobnicate() = 0;
};

//foo.cpp
class Foo : public IFoo
{
  int member;
  void Frobnicate()
  {
    member = 42;
    printf("hello world");
  }
};
IFoo* IFoo::New() { return new Foo; }
p.s. it's not my cup of tea though.

PARTNERS