Jump to content

  • Log In with Google      Sign In   
  • Create Account


Legacy code (what's it and how is related to c++)?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
30 replies to this topic

#1 Nathan2222_old   Members   -  Reputation: -400

Like
1Likes
Like

Posted 21 February 2014 - 07:20 AM

I've been seeing this stuff everywhere and google isn't helping.
Quote from another thread:

. . .
On top of all that is simple momentum -- There's a legacy of C and C++ code in the games industry that's venerable, tested, and works on every relevant platform.

What is legacy code and how/why is c++ described as legacy code?
Is it because it's old?

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32
smile.png
--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy


Sponsor:

#2 LennyLen   Crossbones+   -  Reputation: 3293

Like
14Likes
Like

Posted 21 February 2014 - 07:50 AM

Legacy code basically just means old code that is still in use.

 

More often than not, the term is generally used to describe old code that could be done better using modern techniques, but that continues to be used possibly because the cost of replacing it (or the hardware it is running on) is initially high or because there is other code that depends on it, and nobody wants to risk breaking the dependency.



#3 Nathan2222_old   Members   -  Reputation: -400

Like
-3Likes
Like

Posted 21 February 2014 - 08:03 AM

Legacy code basically just means old code that is still in use.
 
More often than not, the term is generally used to describe old code that could be done better using modern techniques, but that continues to be used possibly because the cost of replacing it (or the hardware it is running on) is initially high or because there is other code that depends on it, and nobody wants to risk breaking the dependency.

so that's why languages have a hard time being as popular as c++. It may be easier, maybe faster and requires less code but it isn't worth changing because the consequence outweighs the advantage.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32
smile.png
--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy


#4 BHXSpecter   Members   -  Reputation: 1112

Like
6Likes
Like

Posted 21 February 2014 - 08:18 AM


so that's why languages have a hard time being as popular as c++. It may be easier, maybe faster and requires less code but it isn't worth changing because the consequence outweighs the advantage.

No that isn't why and legacy code has little to nothing to do with the popularity of something. There are programmers that swear by C++, there are some that swear by Java, others by C#, etc. Each language has its own following and C++ is so widely popular because it was adopted so quickly as the standard language for most software companies. That has started to change over the years as companies shift their focus or develop teams to develop on other platforms. Every language is designed with specific tasks in mind.


"Through vengence I was born.Through war I was trained.Through love I was found. Through death I was released. Through release I was given a purpose."


#5 Karsten_   Members   -  Reputation: 1446

Like
4Likes
Like

Posted 21 February 2014 - 08:19 AM

As stated by Bjarne Stroustrup

 

"There are only two kinds of languages: the ones people complain about and the ones nobody uses".

 

The only reason why there is legacy C and C++ code is because C and C++ was common back then, still is common and will remain common in future (afterall, it is pretty much *the* standard language in software engineering).

If Java or .NET was around back then and it was deemed better than C++, then there would be lots of legacy code lying around in those languages.

 

A good example of this is Microsoft VB6. There is a tonne of legacy VB6 code lying around but unlike C++ the new VB.NET is not backwards compatible so developers are reimplementing it in current (more portable) languages (like C++ and Java).

 

In another 50 years, the original legacy C and C++ code will probably still work so what will it be called? Archaic? In my opinion, if legacy code works, is maintainable and well documented then it is great. It means that it was originally correctly written and used correct "futureproof" technology. Contrast this to code that you need to rewrite every few years because you keep choosing technology that becomes obsolete / dies (I am looking at you VB6!).


Edited by Karsten_, 21 February 2014 - 08:27 AM.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#6 Serapth   Crossbones+   -  Reputation: 5174

Like
2Likes
Like

Posted 21 February 2014 - 08:25 AM

As stated by Bjarne Stroustrup

 

"There are only two kinds of languages: the ones people complain about and the ones nobody uses".

 

The only reason why there is legacy C and C++ code is because C and C++ was common back then, still is common and will remain common in future (afterall, it is pretty much *the* standard language in software engineering).

If C# was around back then and it was deemed better than C++, then there would be lots of legacy C# code lying around.

 

A good example of this is Microsoft VB6. There is a tonne of legacy VB6 code lying around but unlike C++ the new VB.NET is not backwards compatible so developers are reimplementing it in current (more portable) languages (like C++ and Java).

 

That Stroustrup comment is spurious at best.  There are a large number of languages that never become popular but never really go away.  Smalltalk and LISP are too examples that jump to mind immediately.  Then there are tons of domain specific languages, which are almost by definition unpopular and used.  Haskell is probably a good example here, but you could also consider FORTRAN or MATLab in this area.

 

FORTRAN may not be fair on that list, as my understanding is, that bastard is uber popular amongst the math and engineering sets...



#7 Karsten_   Members   -  Reputation: 1446

Like
1Likes
Like

Posted 21 February 2014 - 08:32 AM

Surely your comment just agreed with that quote.

Languages may never fully go away but the popular ones that get used 24/7 do naturally generate legacy code. So again, the sheer popularity of C and C++ is what has caused the influx of legacy code.

 

I honestly have never seen Smalltalk code in the wild (let alone legacy libs) but I come into contact with Lisp quite often via my use of emacs and admittedly I have seen some pretty crusty Lisp (even though it is a slightly different dialect) ;)


Edited by Karsten_, 21 February 2014 - 08:38 AM.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#8 Nathan2222_old   Members   -  Reputation: -400

Like
1Likes
Like

Posted 21 February 2014 - 08:34 AM

As stated by Bjarne Stroustrup
 
"There are only two kinds of languages: the ones people complain about and the ones nobody uses".
 
The only reason why there is legacy C and C++ code is because C and C++ was common back then, still is common and will remain common in future (afterall, it is pretty much *the* standard language in software engineering).
If Java or .NET was around back then and it was deemed better than C++, then there would be lots of legacy code lying around in those languages.
 
A good example of this is Microsoft VB6. There is a tonne of legacy VB6 code lying around but unlike C++ the new VB.NET is not backwards compatible so developers are reimplementing it in current (more portable) languages (like C++ and Java).
 
In another 50 years, the original legacy C and C++ code will probably still work so what will it be called? Archaic? In my opinion, if legacy code works, is maintainable and well documented then it is great. It means that it was originally correctly written and used correct "futureproof" technology. Contrast this to code that you need to rewrite every few years because you keep choosing technology that becomes obsolete / dies (I am looking at you VB6!).

so backwards compatibility is a good thing? I heard C++ is also backwards compatible with C and that struct comes from C while the C++ equivalent is class.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32
smile.png
--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy


#9 Karsten_   Members   -  Reputation: 1446

Like
2Likes
Like

Posted 21 February 2014 - 08:46 AM

so backwards compatibility is a good thing? I heard C++ is also backwards compatible with C and that struct comes from C while the C++ equivalent is class.

 

Definitely. My main interest in the C++ language is the backwards compatibility.

If Java could support old C and C++ code and didn't need a JRE, I would be all over that mofo ;)

 

C++ is mostly backwards compatible with C (in that it is very easy to get C compiling with a C++ compiler). Objective-C also is backwards compatible with C. C++ is a little more strict than C in that it needs explicit casts etc.. but in general it is all good.

 

C++ has structs as well but the only difference between a struct and a class in C++ is that by default everything in it is public. A well designed C++ application can make use of both structs and classes.

 

I might add that although C++ is backwards compatible, the design of the code is different and should be treated as such. New(ish) features like custom deleter functions in smart pointers make dealing with C code much nicer however.

 

I think the best example I can think of is OpenGL which is a C library can be directly consumed by C++ code. Contrast this to using other languages where you have to use a wrapper (a wrapper is a large project to bind the native C code to another language). These things are notorious for becoming very unmaintained and out of sync with the latest version of the original library. Even Microsoft couldn't be arsed anymore with XNA (A fat binding for DirectX 9). Another example is the many Java OpenGL bindings. These things are platform specific (so you instantly lose one of the potential features of Java) and they are also a massive pain to rig up compared to just doing the whole thing in C++ and binding it at compile time (try writing a simple C++ OpenGL application and then try the same thing in Java and make up your own mind).

 

Plus, C and C++ can easily go the other way too. They can call, for example, a Java library or .NET library using libjni or libmono (or even Microsoft C++/clr). Trying to get Java code to call a .NET library is extremely fiddly.

 

That said, some of these features I have just ranted about are not always necessary for games development so it is largely irrelevant to most people. It still comes down to use the language you prefer and can get the game done quickest in ;)


Edited by Karsten_, 21 February 2014 - 09:02 AM.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#10 Nathan2222_old   Members   -  Reputation: -400

Like
1Likes
Like

Posted 21 February 2014 - 08:59 AM

so backwards compatibility is a good thing? I heard C++ is also backwards compatible with C and that struct comes from C while the C++ equivalent is class.

Definitely. My main interest in the C++ language is the backwards compatibility.
If Java could support old C and C++ code and didn't need a JRE, I would be all over that mofo ;)
 
C++ is mostly backwards compatible with C (in that it is very easy to get C compiling with a C++ compiler). Objective-C also is backwards compatible with C. C++ is a little more strict than C in that it needs explicit casts etc.. but in general it is all good.
 
C++ has structs as well but the only difference between a struct and a class in C++ is that by default everything in it is public. A well designed C++ application can make use of both structs and classes.
 
I might add that although C++ is backwards compatible, the design of the code is different and should be treated as such. New(ish) features like custom deleter functions in smart pointers make dealing with C code much nicer however.
 
I think the best example I can think of is OpenGL which is a C library can be directly consumed by C++ code. Contrast this to using other languages where you have to use a wrapper (a wrapper is a large project to bind the native C code to another language). These things are notorious for becoming very unmaintained and out of sync with the latest version of the original library. Even Microsoft couldn't be arsed anymore with XNA (A fat binding for DirectX 9). Another example is the many Java OpenGL bindings. These things are platform specific (so you instantly lose one of the potential features of Java) and they are also a massive pain to rig up compared to just doing the whole thing in C++ and binding it at runtime (try writing a simple C++ OpenGL application and then try the same thing in Java and make up your own mind).
but doesn't backwards compatibility increase the complexity of a language? Supporting old features that can be replaced by new ones.
By putting those two options in one language, don't you increase it's complexity till it becomes so bad?

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32
smile.png
--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy


#11 Karsten_   Members   -  Reputation: 1446

Like
2Likes
Like

Posted 21 February 2014 - 09:13 AM

Well C++ does have a deprecation system. For example std::auto_ptr<T>.

 

Also, if you don't use an old feature of a language. How could that effect your project negatively? Just because the language supports something, it doesn't mean you have to use it. Same with new features, I know a lot of developers I work with tend to overly consume language features because they are "new and cool".

 

Most C and C++ compilers also have a way to specifiy the standard to use via a compile time flag (i.e -std=C++11, -std=C++0x, -std=C99). It also has "non standard" standards support (i.e -std=gnu++0x) and even one that adds basic RAII into GNU C (cant recall the compile time flag).

 

What would you prefer? A slightly more complex language or one that a library you rely on no longer compiles because the language has changed?

Ironically using something like Java or .NET does not solve this because both these languages are compiled using C / C++ so a breakage in the underlying C language has a knock on effect on these entire platforms (i.e porting Java to a new platform is a massive task made almost impossible if the C++ language changes every year).


Edited by Karsten_, 21 February 2014 - 09:23 AM.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#12 Nathan2222_old   Members   -  Reputation: -400

Like
0Likes
Like

Posted 21 February 2014 - 10:40 AM

Well C++ does have a deprecation system. For example std::auto_ptr<T>.
 
Also, if you don't use an old feature of a language. How could that effect your project negatively? Just because the language supports something, it doesn't mean you have to use it. Same with new features, I know a lot of developers I work with tend to overly consume language features because they are "new and cool".
 
Most C and C++ compilers also have a way to specifiy the standard to use via a compile time flag (i.e -std=C++11, -std=C++0x, -std=C99). It also has "non standard" standards support (i.e -std=gnu++0x) and even one that adds basic RAII into GNU C (cant recall the compile time flag).
 
What would you prefer? A slightly more complex language or one that a library you rely on no longer compiles because the language has changed?
Ironically using something like Java or .NET does not solve this because both these languages are compiled using C / C++ so a breakage in the underlying C language has a knock on effect on these entire platforms (i.e porting Java to a new platform is a massive task made almost impossible if the C++ language changes every year).

if it wasn't based of c++.
What's deprecation? Some #include's in c++ are deprecated.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32
smile.png
--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy


#13 Lactose!   GDNet+   -  Reputation: 2416

Like
1Likes
Like

Posted 21 February 2014 - 10:43 AM


What's deprecation?

Deprecation



#14 KnolanCross   Members   -  Reputation: 1158

Like
2Likes
Like

Posted 21 February 2014 - 11:31 AM

As far as my experience goes, the code is not called legacy because it is old, it is because no one supports it (and, therefore, no one understands properly how it works).


My blog on programming and games.
http://16bitsflag.blogspot.com.br/

#15 Nathan2222_old   Members   -  Reputation: -400

Like
-1Likes
Like

Posted 21 February 2014 - 12:04 PM

As far as my experience goes, the code is not called legacy because it is old, it is because no one supports it (and, therefore, no one understands properly how it works).

so does that means they don't understand what runs their system?
If this is true, what is the benefit of having what you don't understand and isn't supported?

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32
smile.png
--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy


#16 Alessio1989   Members   -  Reputation: 1657

Like
0Likes
Like

Posted 21 February 2014 - 12:33 PM

 

 

so backwards compatibility is a good thing? I heard C++ is also backwards compatible with C and that struct comes from C while the C++ equivalent is class.

Definitely. My main interest in the C++ language is the backwards compatibility.
If Java could support old C and C++ code and didn't need a JRE, I would be all over that mofo ;)
 
C++ is mostly backwards compatible with C (in that it is very easy to get C compiling with a C++ compiler). Objective-C also is backwards compatible with C. C++ is a little more strict than C in that it needs explicit casts etc.. but in general it is all good.
 
C++ has structs as well but the only difference between a struct and a class in C++ is that by default everything in it is public. A well designed C++ application can make use of both structs and classes.
 
I might add that although C++ is backwards compatible, the design of the code is different and should be treated as such. New(ish) features like custom deleter functions in smart pointers make dealing with C code much nicer however.
 
I think the best example I can think of is OpenGL which is a C library can be directly consumed by C++ code. Contrast this to using other languages where you have to use a wrapper (a wrapper is a large project to bind the native C code to another language). These things are notorious for becoming very unmaintained and out of sync with the latest version of the original library. Even Microsoft couldn't be arsed anymore with XNA (A fat binding for DirectX 9). Another example is the many Java OpenGL bindings. These things are platform specific (so you instantly lose one of the potential features of Java) and they are also a massive pain to rig up compared to just doing the whole thing in C++ and binding it at runtime (try writing a simple C++ OpenGL application and then try the same thing in Java and make up your own mind).
but doesn't backwards compatibility increase the complexity of a language? Supporting old features that can be replaced by new ones.
By putting those two options in one language, don't you increase it's complexity till it becomes so bad?

 

 

A (almost) compatibility with C is a feature of the C++ programming language, read more here: http://www.stroustrup.com/bs_faq.html#whyC

 

For the legacy code question: it exist for an ancestral and universal common law in the programming world that could be summarize in “if it works don't touch it”. Many people don't argue with it or they have slightly different forms (I honestly prefer this: "if it works  and it doesn't create big issues, don't even try touch it or I will cut your fingers!")...

A good example of legacy code in the game industry could be the use of DirectInput: DirectInput it's deprecated (last version came with DirectX SDK 8.x), but it still works well and for many games its limitations are not a big issues, plus you can use it to support all the HIDs (human interface devices) that are not supported by other APIs (like xinput)... DirectInput actually is used in most AAA games and game engines/SDK (Valve's Source, Crytek CryEngine, Torque 3D, Unreal Engine, etc...).


Edited by Alessio1989, 21 February 2014 - 12:49 PM.


#17 Karsten_   Members   -  Reputation: 1446

Like
0Likes
Like

Posted 21 February 2014 - 12:43 PM

As far as my experience goes, the code is not called legacy because it is old, it is because no one supports it (and, therefore, no one understands properly how it works).

Agreed. Although I guess that as soon as a dependency our code relies on has had support dropped, no matter how new the code is, it is suddenly "legacy". This is why portable code is very important (especially nowadays where for some reason companies think experimental == modern)
 
Although I find it quite amusing how much of Microsoft's legacy technology these days is actually outliving its successors. I have already placed my bets on MFC actually outlasting WPF (a technology at least 3 generations newer).
 

so does that means they don't understand what runs their system?
If this is true, what is the benefit of having what you don't understand and isn't supported?

Because if it still works, then it is still useful. If it is an old crusty black box, then that is a shame but it still probably doesnt justify a rewrite.

We dont understand whats behind closed-source software and yet people are more than happy to use that.

I guess in some ways, closed-source software is deprecated as soon as you have purchased it because you cannot maintain the code yourself.

(Full disclosure, I am a BSD user/developer and advocate open-source for everything people do).


Edited by Karsten_, 21 February 2014 - 12:49 PM.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#18 Nathan2222_old   Members   -  Reputation: -400

Like
-1Likes
Like

Posted 21 February 2014 - 01:21 PM

As far as my experience goes, the code is not called legacy because it is old, it is because no one supports it (and, therefore, no one understands properly how it works).

Agreed. Although I guess that as soon as a dependency our code relies on has had support dropped, no matter how new the code is, it is suddenly "legacy". This is why portable code is very important (especially nowadays where for some reason companies think experimental == modern)

Although I find it quite amusing how much of Microsoft's legacy technology these days is actually outliving its successors. I have already placed my bets on MFC actually outlasting WPF (a technology at least 3 generations newer).

so does that means they don't understand what runs their system?
If this is true, what is the benefit of having what you don't understand and isn't supported?

Because if it still works, then it is still useful. If it is an old crusty black box, then that is a shame but it still probably doesnt justify a rewrite.
We dont understand whats behind closed-source software and yet people are more than happy to use that.
I guess in some ways, closed-source software is deprecated as soon as you have purchased it because you cannot maintain the code yourself.
(Full disclosure, I am a BSD user/developer and advocate open-source for everything people do).
it may not matter to the user but shouldn't it matter to the company that owns the software.
It's like that php blog i read: Everything is bad in it but just because it's all you've been using and come to see, you don't see it necessary to change.
And another one about how legacy code is caused: It's not a single programmer that causes it but a whole bunch of programmers that have come and seen that same weird code but thought, i know it definitely needs to be written but if it hasn't been changed, why should i change it.
The more you believe it works and keep trying to justify it, the more that gets added to it till it's too late to rewrite it without any significant consequence (except you find a language that uses one line to rewrite the whole program).

@alessio: the c++ fqa contradicts and almost condems everything in that faq.

I have no problem with closed source software. I am a happy windows user. I don't know what BSD is.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32
smile.png
--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy


#19 Lactose!   GDNet+   -  Reputation: 2416

Like
1Likes
Like

Posted 21 February 2014 - 01:39 PM


I don't know what BSD is.

http://lmgtfy.com/?q=BSD



#20 Ravyne   Crossbones+   -  Reputation: 6728

Like
4Likes
Like

Posted 21 February 2014 - 03:52 PM

 

As far as my experience goes, the code is not called legacy because it is old, it is because no one supports it (and, therefore, no one understands properly how it works).

so does that means they don't understand what runs their system?
If this is true, what is the benefit of having what you don't understand and isn't supported?

 

There's no benefit, other than that the system works and will likely continue to work. The implication of this definition of "legacy" is that no one is left who understands the old code precisely enough to replace it with newer, better, cleaner code. Happens all the time -- some medium-sized utility at a large warehouse operation becomes critical to the business, developed by one lone programmer, and hacked to add new features over the years, and suddenly that programmer leaves the company, retires, or dies. The business relies on that software, but can't risk changing it and can't afford to hire a consultant to come in and analyze it to the necessary degree. You'd like to think that just any programmer can come in and read the code and know what's going on, but its not the case in reality. In reality there are all sorts of little assumptions and gotchas in most code bases (particularly of the type I describe here), and documentation, if it even exists, is often outdated for just plain wrong.

 

Yes, the business is precariously positioned to rely on such software, but what can they do?

 

 

There's somewhat less of this in the games industry, for example, but I recall reading in an article that Madden Football -- all the way up until its Xbox 360 and PS3 incarnations -- still had some C code in it that had originated in the Sega Genesis version. The first few Halo games, originally developed for the MAC, had a codebase that sort of hacked some C++-like features into their C codebase (The mac platform didn't have great support for C++ back in the day, and their frameworks to this day are written in (or at least exposed as) Objective-C rather than C++ or even vanilla C). I'd wager that the latest unreal engine has code stretching back to the original unreal.

 

Legacy code is just older code that's either difficult or unfeasible to replace, but which is nonetheless necessary to continue using. It's most often stated in relation to C++ just because C and C++ were among the first very popular, widely used languages. But there's a non-trivial amount of legacy COBOL and FORTRAN code running all kinds of finance and business institutions. In fact, if you understand either one along with the hardware and related software systems of the day as well as the old-timers did, and also a modern language well enough to re-implement it in a more-modern language, you can probably earn yourself a half-million-dollar salary or more through consulting work.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS