Thread: Batch code editing (was: [GD-General] C++ analyzers?)
Brought to you by:
vexxed72
From: Grills, J. <jg...@so...> - 2002-07-18 20:45:05
|
I frequently use perl to do these sorts of things. I have a small template perl script that I customize a bit every time I need to do this. It's pretty smart too -- it's do the replacement in the file, and check for changes, and only if it changed will it check the file out of source control (perforce, of course) and then update its contents. j -----Original Message----- From: Thatcher Ulrich [mailto:tu...@tu...] Sent: Thursday, July 18, 2002 3:21 PM To: gam...@li... Subject: Re: [GD-General] C++ analyzers? On Jul 18, 2002 at 12:41 -0700, Brian Hook wrote: > Quite true, and this illustrates my earlier comments of how bad most > software development tools. Something as conceptually simple as > renaming a variable can be incredibly difficult to manage. Even using a > standard automated tool like perl or sed/awk you run into the problem > that there's no context. > > We have tools to automatically generate code and do all other kinds of > fluff crap, but if you actually want something that can go through and > rename all instances of "m_foo" for all instances of class "CBar", it > doesn't seem possible. Well, the compiler can sure help: 1. rename "m_foo" to "m_foobar" in the header 2. compile 3. visit each compile error and fix by hand (or with an editor macro if it's a big job) I've found that manual brute force takes much longer in theory than in practice. Once I had to rename a 3D vector class from "vector" to "vec3" throughout a working game; I was dreading it, but it took all of about 30 minutes. That's by far the worst case I've ever encountered. Sure it would be nice if it took 10 seconds, but it's not something most people have to do every week. -- Thatcher Ulrich http://tulrich.com ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Brian H. <bri...@py...> - 2002-07-18 21:09:39
|
But does it do context and type sensitive changes? Will it only change m_uFlags to m_uEntityFlags in only those instances where's it referenced as an entity? Most search and replace tools, no matter how elaborate, aren't designed to actually understand the actual code itself. That's my beef with doing things manually. If you change the name of a variable you can easily find the problems by compiling and fixing errors, but that's tedious and error prone. Also, silent errors can get introduced with search and replace that's done incorrectly or that doesn't handle all cases: int foo; int bar; int foobar; int blahbar; s&r foo -> blah suddenly all your foo are blah, which is what you want, but now your foobar are blahbar, which is NOT what you wanted. It's this kind of tedium and risk that often prevents programmers from willingly making sweeping changes that need to be done. When there's a global variable called "gameState" and it can/should be put into an appropriate object, but it would require changing a zillion instances of code and possibly conflicting with member variables called "gameState" so that automatic tools don't do the right thing, then often programmers just say "leave well enough alone". And you have bad code just sitting there. But, more specifically, it's something that a computer should be able to do. In fact, it's something that computers were DESIGNED to do -- automate tedious and repetitive tasks. It baffles me why I can't say "Rename CFoo::update() to CFoo::fooUpdate()", which avoids the whole s&r problem with collisions between identically or similarly named identifiers. The above is an active operation, however, and I would just be joyous with passive operations that, as I mentioned in my original e-mail, show me obvious dumb things that should be fixed, like classes defined and never used; members defined but never used; etc. You'd get lots of warnings, but they'd be easy enough to fix or ignore (e.g. padding members in structures "short dummy" or "char pad[4]", etc.) Maybe I'm being na=EFve, but this seems like the kind of thing that = would be trivially easy to implement (compared to writing a compiler + IDE), yet all we keep getting are the basic things like automatic expansion of member variables when you type "foo->". Hell, and that doesn't work 95% of the time anymore in MSVC =3D| And yes, maybe PC-Lint is the way to fix it, but damn, it sure does look...crusty. Brian |
From: Thatcher U. <tu...@tu...> - 2002-07-18 21:32:06
|
On Jul 18, 2002 at 02:09 -0700, Brian Hook wrote: > But does it do context and type sensitive changes? Will it only change > m_uFlags to m_uEntityFlags in only those instances where's it referenced > as an entity? Most search and replace tools, no matter how elaborate, > aren't designed to actually understand the actual code itself. > > That's my beef with doing things manually. If you change the name of a > variable you can easily find the problems by compiling and fixing > errors, but that's tedious and error prone. Also, silent errors can get > introduced with search and replace that's done incorrectly or that > doesn't handle all cases: > > int foo; > int bar; > int foobar; > int blahbar; > > s&r foo -> blah > > suddenly all your foo are blah, which is what you want, but now your > foobar are blahbar, which is NOT what you wanted. Forgot to mention another handy technique: search & replace with an intermediate name, like "m_foobar_TEMPORARY_CRAZY_UNIQUE_IDENTIFIER", fix the errors, then do a global perl script on the unique identifier. It'll be hard to turn foobar into blahbar that way. > Maybe I'm being na?ve, but this seems like the kind of thing that would > be trivially easy to implement (compared to writing a compiler + IDE), > yet all we keep getting are the basic things like automatic expansion of > member variables when you type "foo->". Hell, and that doesn't work 95% > of the time anymore in MSVC =| Well, yeah, I agree you have a point, I'm just throwing out random practical advice that I'm sure everybody knows already. The fundamental problem is that C++ is incredibly hard to parse; in fact it's still an unsolved problem :) But, I believe this new generation of compilers (GCC 3, and VC.net or whatever) is much better about exporting program metadata, so maybe it will be possible to build tools off that. -- Thatcher Ulrich http://tulrich.com |