Reputation: 5217
Is it possible to find all one line statements like for
, if
or else
and add brackets to them if there is no bracket?
is there a helpfull function in eclipse or can i use any kind of regex, grep or something else? If its not possible to add the bracktes automaticily, it would be also helpful to find all places in the code where such a function is used.
Upvotes: 0
Views: 125
Reputation: 12205
This is almost always a bad idea. For one thing you better hope the the regex you run through your code doesn't mess up at a corner case and destroy your code. It also messes up source control by putting your name all over the place instead of the actual person who wrote it. It also wastes valuable time for yourself that you could be using to fix bugs/adding enhancements.
If the coding style really bothers you just change it whenever you find it by hand and eventually you will fix most of the occurrences.
Upvotes: 1
Reputation: 82559
I think you'd be better off using the code formatter in Eclipse for this instead of a regex. It just seems cleaner to do that.
Of cousre, it will format everything, so make sure you have every possible setting to your liking. You'll probably find it's more trouble than it's worth.
If you really want your code cleaned up, just tell your programmers that going forward, to use this new standard, and if they see existing code not following the standard to fix it. Perhaps ask them to check the files once over before checking in.
Personally, I think mandates like this are silly. Sure, they can lead to inconsistent code between developers, but I think any developer is capable of reading either way (especially if they work with developers who do it the other way) and that fights like that between developers over it are quite silly. (Although if it's a huge majority, I think the minority just needs to conform. I'm on a group of 10 programmers, and the others are gung-ho over Hungarian notation. I object to it, but that's what the standard is, so that's what I do. I don't have to like it, but as a professional that's what you do.)
Upvotes: 5