Fog Creek Software
Discussion Board

Imagine a language which...

Something I just thought of, kind of inspired by the Case Sensitive thread. Imagine a language which allowed you to define certain style parameters. For example, if you could set a rule that said 'member variables must be prefixed with m_' or 'variables must have a lower case first letter' or 'variables aren't case sensitive'. Would it be cool, and useful, or would it be dumb and foolish?

Mr Jack
Wednesday, July 30, 2003

You better inform the linker about this.

Just me (Sir to you)
Wednesday, July 30, 2003

I can't see how the linker need care.  The casing and structure of naming is a compiler table issue, for variables at least.  Global variables pop into the Linker's ambit but so long as it maintained the casing and the link table was sane that wouldn't matter either.

If you want to create a language that does this, go ahead, that's what compiler tools are for.  I'd recommend anyone to design their own language at some point.  Mini-task specific languages can be very useful for some classes of problems.  And understanding how syntax analysers work, opcodes and how they can make or break the efficiency of a language only makes writing code in any language easier and debugging less of a black art.

If you do create a language to do this then I'd also use keywords to help the syntax analyser work out what was and wasn't a variable, such as var int m_i for example.

Simon Lucy
Wednesday, July 30, 2003

I think it would be a bad idea unless it was a standard in the language.  Having the naming convention be user-defined will only make code in that language into a Tower of Babel.  No one will be able to read other's code.

I think the python decision to try to limit the number of ways to format things is great.  I am a C programmer and it still annoys me when people don't brace or indent the way I do, and to have 300 different hungarian notations.

Wednesday, July 30, 2003

Hungarian notation is dumb, ok, but I prefer to choose the way I indent. If I receive some badly indented code, well, it can be fixed with GNU indent.

Leonardo Herrera
Wednesday, July 30, 2003

I have a VB6 addin which does this. It's template driven (so you can use your own in-house style).

It can create the template based on existing code (i.e. don't have to spend time learning how to do this) - Obviously you need a small project with at least 1 example of everything.

It will reformat a module/project to conform to your template style.

If there is enough interest, I'll put a link up for free downloads.

I have also got a another tool which does a similar thing for error handling blocks. It will "munge" the template based code into your project in one go, or can be used automatically (a new function will get the template code added).
This one isn't quite finished yet (needs more testing).


Wednesday, July 30, 2003

Whether it would be "cool" or not is not really that interesting to me.  Would such a device solve a real-world problem?

I think it would.  We have a tool called FXCOP which analyzes managed assemblies looking for all kinds of problems, from suspicious link demands to interfaces not starting with "I".  It's a great tool, but the problem with it is that you have to remember to run it on the compiled binary post facto. 

If the compiler itself could incorporate FXCOP rules then the problems would be caught much sooner, before the suspicious code was even checked in.


Eric Lippert
Wednesday, July 30, 2003

So if you're working on a project with 20 people, every time you look at a piece of code, you're going to check it out, run your own automatic formatter on it, modify it, then check it back in?

Sounds like a good way to piss off your co-workers.  It would be nice if all projects had a coding standard, but that's not the case, unfortunately.

Wednesday, July 30, 2003

Actually Andy, presumably you would have project wide standards, but I must admit I would prefer to see an editor which presents the code to me according to a stylesheet or something, no matter how it is formatted. Since there is software to do the reformatting anyway I don't see that this could be too big a job? Anyway, that way everyone would get to read code exactly how they want to.

Thursday, July 31, 2003

Correct me if I'm wrong, but I think there are plugins for Eclipse or JEdit that can do this kind of check for Java. Of course, it is not integrated in the compiler.

Thursday, July 31, 2003

*  Recent Topics

*  Fog Creek Home