The Artima Developer Community
Sponsored Link

Weblogs Forum
Aren't C++ Programmers People Too?

18 replies on 2 pages. Most recent reply: Nov 13, 2007 12:14 PM by Axel Plinge

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 18 replies on 2 pages [ 1 2 | » ]
Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Aren't C++ Programmers People Too? (View in Weblogs)
Posted: Aug 23, 2003 2:05 PM
Reply to this message Reply
Summary
The industry needs refactoring tools for C++. Now.
Advertisement

C++ programmers are people too, aren't they? You wouldn't think anyone thought so, the way the industry looks today. Java started its run in the late 90s and it rapidly became the lingua franca of programming. Over night, authors started using it for all of their examples in books and articles. Certainly this was response to the market, but Java is also a much more succinct language. If you are going to write about design, Java gives you a better chance of fitting a code snippet on a page. The net effect, however, is that if you look around for evidence of C++'s continued existence, it is pretty easy to miss it. And, if you are one of these invisible C++ programmers and you are aware of that tools are available for Java but not C++, well, you should be screaming. C++ was my first OO language and every time I go back to program in it I notice the lack of support.

A few weeks ago, I was working with a team whose code is split right down the middle. Half of the code is Java and the other half is C++. At the beginning of each iteration, the team members sign up for tasks. When someone walks into the room each morning you can pretty much tell whether they'll be working in C++ or Java. Their faces tell the story. The people who are going to be working in Java march in confidently and start up their Java-based IDE, then they go to get coffee while it loads (yes, there still are some issues in Java-land). When they get back with steaming cups in hand, they look around at the code, find the methods they need to change. They click a menu item and it shows them all of the places that send a particular message. Then they start going through the work of carving out a space to work with their code. They click the mouse around to extract interfaces and methods automatically so that they can get some tests in place for their changes. The C++ programmers come in and bring up vi or emacs (they load quickly so no coffee for the C++ guys) then they browse around the code manually and start to figure out where to make their changes. Figuring out what uses what is often a blind-alley search. When they are ready to break some dependencies, they sit there and try to manually peel off interfaces by introducing virtual functions. They create new header files and extract methods by hand, all the while hoping and praying that they aren't breaking anything. Without an automated tool to check their refactorings it is a nerve-wearing process and it's also several times slower. They know that the Java code is getting better, but it is hard to feel the progress on the C++ side. I don't think the lack of coffee has anything to do with it.

Occasionally, some C++ teams I visit don't know what refactoring tools are out there. I was showing a team a testing technique a while back. The technique was language independent, so I pulled up a Java IDE. Over the course of my coding I found a method name that I didn't like. I pulled down a menu and hit rename. When I typed in the new name it was replaced every place it was used. Not every place in the file, every place it was used. Three of the team members recognized what they saw when I did it and they shouted "NNNOOO WAAAAAYYY!!!" I think I could have induced dead faints if I'd shown an automated extract method refactoring.

The sad thing is, it shouldn't be like this.

The first research into automated OO refactoring was done by Bill Opdyke and Ralph Johnson in the early 1990s, in C++. After that, John Brant and Don Roberts developed the first Smalltalk refactoring browser. Later, Martin Fowler wrote the book 'Refactoring.' That book and Extreme Programming really put refactoring on the radar screen. Java vendors scrambled to build refactoring tools into their IDEs. After all, it was the lingua franca, the language everyone is using, right?

In a few weeks, I'll be visiting another C++ team. This isn't atypical. There is a lot of C++ out there. More than anyone would imagine from looking at literature in "the industry." I wish I could tell them that someday there will be a refactoring tool for C++. For teams with large existing code bases it would be an immediate boost.


Frank Mitchell

Posts: 37
Nickname: fmitchell
Registered: Jan, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 23, 2003 4:11 PM
Reply to this message Reply
One of the problems with C++ is that it's a complex language with a lot of interacting features. (One former C++ compiler writer complained to me bitterly and at length of all the problems implementing Sun's C++ compiler.) Not all compilers implement all the ANSI/ISO spec; some may have proprietary extensions, others may use older definitions of the language.

A refactoring tool must guarantee that transformations do not change functionality. At best one could develop a C++ refactoring tool for one particular variant of C++. The standard would be a good choice, although pretty complex; a minimal subset of C++ might provide the most bang for the buck, as long as it could flag constructs it couldn't parse or might not handle reliably.

Contrast to Smalltalk or Java, the two languages with the most refactoring support. Java has a very clear specification; between 1.1 and 1.5, the Java language hasn't changed very much: assertions, strictfp, a few tweaks to the threading model. Smalltalk implementations vary, but Smalltalk syntax is pretty consistent (and minimal). Also, from what I understand, Smalltalk refactoring tools either come from with a Smalltalk environment, or target just one enviornment.

Daniel Yokomizo

Posts: 22
Nickname: dyokomiso
Registered: Sep, 2002

Re: Aren't C++ Programmers People Too? Posted: Aug 25, 2003 6:07 AM
Reply to this message Reply
As Frank Mitchell said C++ is a really complex language, comparing to Java or Smalltalk. It's hard to parse correctly and the semantics is a bitch (e.g. execution points, undefined behaviour in expression evaluation ordering, template instantiation rules, const vs. volatile vs. whatever).

Sure a Refactoring tool for C++ would be great, or a syntax sensitive search-engine (e.g. find all do while loops that use break), but these tools would require too much work to complete, usually more than the developers have available. The only alternative is extending compilers, but there are few open C++ compilers. IIRC the gcc people don't want to expose the parse tree internals due to political issues (exposing them would open a door to people circumvent the gpl in some weird ways and embed its functionality in proprietary tools), so if you want to add this extension you need to fork the gcc and maintain yourself.

A final thought. If you really miss these tools in C++ you should start a project to do it. It will take time, and require help from other programmers, but in the end you'll help yourslef and the community.

Carlos Perez

Posts: 153
Nickname: ceperez
Registered: Jan, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 26, 2003 12:18 PM
Reply to this message Reply
Michael,

Nice, hilarious piece.

The big problem of course is the complexity of writing a C++ parser, add to that the additional complexity introduced by the preprocessor. The only reasonably possibility I can think of is if IBM donated the VisualAge C++ compiler to the community. Then it just might be possible, till then, you just have to be a masochist to work as a C++ programmer.

Carlos

Carlos Perez

Posts: 153
Nickname: ceperez
Registered: Jan, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 26, 2003 12:21 PM
Reply to this message Reply
Wait a minute here,

Have you guys ever used the Sniff++ tool, it makes it so much easier to find things. Although it doens't have refactoring, its better than nothing!

Carlos

Ian Rae

Posts: 21
Nickname: ianrae
Registered: May, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 27, 2003 7:32 AM
Reply to this message Reply
The complexity of C++ is daunting but there is certainly a market. It's surprising there aren't better tools. Take MS-DOS. It was an ugly little "operating system" but by DOS 5 the development tools for it were quite good. Features like the bizarre terminate-and-stay-resident trick or the byzantine high-memory/extended memory quagmire became straight forward. Can RenameMethod in C++ be that much harder?

Zohar Melamed

Posts: 28
Nickname: zohar
Registered: Aug, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 27, 2003 9:22 AM
Reply to this message Reply
Refactoring IDE's working at the semantic level ( second generation IDE's) have only been available for Java in the last 2+ years. Even today most mainstream vendors like borland are pursuing the traditional first generation syntactic approach by adding more wizards, and other shallow features.

Ditto VS.NET


The breakthrough in Java came from Jetbrains, not a major vendor...

One big problem, which is usually overlooked is the long compile times in C++ compared to Java.


IntelliJ will constantly recompile the class you are working on in the background to keep the parse tree in sync.

How will that work in C++ ?

The compilation just takes far too long....

This is a problem in many other respects e.g. continuous integration, test driven development , etc.

A C++ project I use to work on took 5 hours for a full build...

Some of the modules ( especially where COM met Templates) where 30 min + compiles.

Having worked with C++ and now using the new breed of Java tools, I must say I feel sorry for anyone who has to program C++ for a living.

Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 27, 2003 11:04 AM
Reply to this message Reply
> A C++ project I use to work on took 5 hours for a full
> build...
>
> Some of the modules ( especially where COM met Templates)
> where 30 min + compiles.
>
> Having worked with C++ and now using the new breed of Java
> tools, I must say I feel sorry for anyone who has to
> program C++ for a living.

There are some nicer C++ projects with better dependency structures, but many projects are just very tough to work on.

I think that there is one refactoring that may not take a very deep analysis but would very useful: extract interface.

The methods you want to extract to an interface are already virtual, it seems pretty easy. If they are non-virtual, I think that the only problem is when there are methods in subclasses with the same signature. If you made those methods virtual it could change behavior.

A tool that aids interface extraction and helps people refactor includes could help bring compile times under control.

It would be a start, and people really need that start.

I agree that it would be best to target one compiler.

Bill Burris

Posts: 24
Nickname: billburris
Registered: Aug, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 27, 2003 1:06 PM
Reply to this message Reply
A question to ask ourselves is: Why am I using C++?

Here are some of my answers.

In 96 when I looked at Java, it didn't look like a general purpose language, and I didn't see an easy way to mix Java and C++. At the time I was thinking of taking a second look at Java, C# made an appearance.

Now that my code is a mix of C++ and C#, here are the problems.

I started befor C# existed (legacy code).
No .NET support for serial ports or GPS receivers.
No .NET support or device drivers for hardware that I use.
Transition between managed and un-managed code is a problem for time critical code.

A C++ refactoring tool in Visual Studio might come in handy, but I would rather see .NET support for serial ports, and venders of specialized plug-in cards supporting .NET.

If Java and .NET were complete general purpose environments there would be less need for C++. Leave C++ to the device driver developers.

A tool for translating C++ to C# would be more useful then a C++ refactoring tool.

If your only reason for using C++ is legacy code, it might be worth considering tools for translating C++ to C# or Java. One advantage of using C# is that you can easily combine your legacy C++ code and new C# code into the same application.

Bill

Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 27, 2003 1:25 PM
Reply to this message Reply
> If your only reason for using C++ is legacy code, it might
> be worth considering tools for translating C++ to C# or
> Java. One advantage of using C# is that you can easily
> combine your legacy C++ code and new C# code into the same
> application.

I hear you, but there are many applications that simply aren't going to make it to C# or Java for a variety of reasons. I've seen quite a few of them.

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 27, 2003 9:17 PM
Reply to this message Reply
> > If your only reason for using C++ is legacy code, it
> might
> > be worth considering tools for translating C++ to C# or
> > Java. One advantage of using C# is that you can easily
> > combine your legacy C++ code and new C# code into the
> same
> > application.
>
> I hear you, but there are many applications that simply
> aren't going to make it to C# or Java for a variety of
> reasons. I've seen quite a few of them.

Even applications that theoretically could make it to C# or Java by nature of what they do may not because of how they do it. What would be the algorithm for translating functions that belong in a namespace but aren't tied to an object. One article by Scott Meyers http://www.cuj.com/documents/s=8042/cuj0002meyers/ actually advocates putting as little in a class as possible. Translating a class and all of its non-member non-friend functions would be a non-friendly task.

I'm going to go out on a limb here and say that for anything but the most trivial programs, translating C++ to any other language is a futile task. I'm sure coming up with tools to make things like refactoring easier is possible, but I don't think it will ever be easy. Would such a tool even be possible? I'm guessing, theoretically, you could do the translation of managed C++ to C#, but once you have unmanaged code doing unmanaged things, how exactly would that work?

What about all those void * and casts? The more I think about this, the more it hurts. And I don't even think I've scratched the surface of all the things that could be an issue, given I haven't done any heavy C++ coding in years.

Uwe Schnitker

Posts: 9
Nickname: uwe
Registered: Aug, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 28, 2003 1:10 AM
Reply to this message Reply
>
> Sure a Refactoring tool for C++ would be great, or a
> syntax sensitive search-engine (e.g. find all do while
> loops that use break), but these tools would require too
> much work to complete, usually more than the developers
> have available. The only alternative is extending
> compilers, but there are few open C++ compilers.

Well, some people try to parse C++ anyway. But I think
if one wants to focus on the real stuff (refactoring) it
is best to use a compiler frontend.

So, if one can afford a huge amount of money, one can solve
the problem by buying the EDG frontend - which, BTW, can
be set to several compatibillty modes (MS, GCC) if really
desired. Not an option for an Open Source project, though.

> IIRC the
> gcc people don't want to expose the parse tree internals
> due to political issues (exposing them would open a door
> to people circumvent the gpl in some weird ways and embed
> its functionality in proprietary tools), so if you want to
> add this extension you need to fork the gcc and maintain
> yourself.

Is this really true (any more)?

IIUC, there are several Open Source projects using the
(official?) GCC as a frontend to specific tools, e.g.
for generating XML descriptions of programs, for creating
interfaces to other systems (databases?), etc. pp.

No refactoring tool project as of now, AFAIK.

But based on experiences of such project, maybe someone
will ...

> A final thought. If you really miss these tools in C++ you
> should start a project to do it. It will take time, and
> require help from other programmers, but in the end you'll
> help yourslef and the community.

Uwe Schnitker

Posts: 9
Nickname: uwe
Registered: Aug, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 28, 2003 1:51 AM
Reply to this message Reply
> > If your only reason for using C++ is legacy code, it
> might
> > be worth considering tools for translating C++ to C# or
> > Java. One advantage of using C# is that you can easily
> > combine your legacy C++ code and new C# code into the
> same
> > application.
>
> I hear you, but there are many applications that simply
> aren't going to make it to C# or Java for a variety of
> reasons. I've seen quite a few of them.

Don't forget that quite a lot of people really like to
program in C++. I'm one of them.

I'm very jealous about these good "Agile Programming" tool
support for Java (and C#?), but from a pure language view
I'd never even consider using one of them. (Note that this
is not single-mindedness. I'd consider using a lot of other
languages.)

I want to design and program multi-paradigm (OO, generic,
sort-of-functional), so I need a language which supports
that either explicitly, like C++ (or Ada - hmmm?), or
implicitly like dynamically typed OO-languages (e.g. Ruby).
("Barfuss oder Lackschuh, Sekt oder Selters", in German)

While C++ and (what I've seen so far from) Ruby align well
to the way I think, those OO languages which try to
overcome the problems of static typing by good reflection
instead of templates, and the lack of what-I-call-in-my-
great-deal-of-ignorance-just-"closures" by special features
(delegates in C#, ... in Java?) instead of good function
object support do not.

So I'd rather have better tools for the language which
allows me to express designs the way I think about them,
than limit the way I think about designs to fit a language
with better tool support.

(Note that I speak about >>my<< way of thinking. I know
that a lot of people think differently, and I don't have
any problems with that - unless they want to impose on me.)

One conclusion for me is that a refactoring tool for C++
must include some very C++ specific refactorings which
are not even known today:

- make free function from member function
- make function object from (free or member) function
- make template from (free or member) function
- make template from class
- change function pointer to function object (pointer)
- change C-style callback (incl. void*) to functor callback

- and probably all the vice versa refactorings, too

I fear that a "very simple" refactoring tool with Java-like
functionality only would encourage people to go forward on
that evil "design like its Java, code in a C++ subset" path.

This would be a really great step - even a jump - forward,
but lead to a dead end nevertheless.

(Don't get me wrong on this. I'd like to see the "very
simple" tool as a very first step in an evolving project.
I'd just not want to wait for C++ specific refactoring for
too long.)

Stephen Hutton

Posts: 6
Nickname: shutton
Registered: Aug, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 29, 2003 8:59 AM
Reply to this message Reply
> The big problem of course is the complexity of writing a
> C++ parser, add to that the additional complexity
> introduced by the preprocessor. The only reasonably
> possibility I can think of is if IBM donated the VisualAge
> C++ compiler to the community. Then it just might be
> possible, till then, you just have to be a masochist to
> work as a C++ programmer.

Hmm, what is special about the VisualAge C++ compiler?

The community already has gcc and there is gccxml:
http://www.gccxml.org/HTML/Index.html
which is already being put to good use, e.g. to
create python bindings for C++ classes:
http://www.boost.org/libs/python/pyste

Carlos Perez

Posts: 153
Nickname: ceperez
Registered: Jan, 2003

Re: Aren't C++ Programmers People Too? Posted: Aug 29, 2003 3:40 PM
Reply to this message Reply
What's special about visualage C++?

You might want to take a look at this open source project:

http://ovid.tigris.org/Ephedra/

read what it says about it.

Regards,

Carlos

Flat View: This topic has 18 replies on 2 pages [ 1  2 | » ]
Topic: Aren't C++ Programmers People Too? Previous Topic   Next Topic Topic: The Why Diarize Song

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use