As detailed by the previous answers, there are both IDEs and Programming languages do have support for this.
Support comes in three general categories:
- Documentation in the code that must be interpreted by the IDE / Compiler / Consumer, these could be interpreted at runtime is you write the code to interpret them
- You can define your own Type definitions that can enforce some constraints at compile time, and others at Runtime
- Direct support in the language runtime
I'll get to the specific support scenarios, but lets deal with the biggest issue that you haven't described... Why?
How important is it to know all of this information about a variable: lowest_integer_allowed_to_set_as_upper_bound_in_game_mode which is effectively including these metadata:
- type: integer
- name: lowest upper bound
- comment: lowest value that can be set in game mode
In terms of reading the code, the type itself is not always as useful as you think, the intent of the variable however is. A well designed class structure should be able to convey most of the intent from the name and structure alone, however it is useful to include comments if you think the intent is still ambiguous.
Many IDEs already provide this support natively, type is a common standard feature however most languages will support a form of structured comments that can be parsed form the source code by a separate process, this makes it less a feature of the language itself and more of a convention and tools that IDEs can use. The following is a standard Doc Comment in C#:
/// <summary>The lowest integer allowed to set as the upper bound in game mode</summary>
int lowest_bound = 10;
The Visual Studio IDE shows these summary comments in a tooltip when you hover over the member field/property reference:
The major caveat to this is that it only works on member level definitions or classes themselves, not on local variables within methods. This is due to the way the comments are compiled and is a generally accepted limitation within methods because you can see and use standard code comments to document in these cases.
There is also JSDoc for javascript that is very similar, however it is possible to document local variables in the function doc comment, makes things a little clumsy to maintain but it can work
One way to get around the local variable documentation issue is to define a separate class to hold the variable values, this is not always practical but can be especially useful if you need to pass these variables around or need to defined them frequently
public class Options
{
/// <summary>The lowest integer allowed to set as the upper bound in game mode</summary>
int lowest_bound = 10;
}
How does this idea compare to existing solutions for managing the trade-off between descriptive naming and code readability (e.g., comments, documentation strings)?
Well this IS using comments instead of going over the top with naming conventions.
Could this approach effectively improve code maintainability and developer productivity?
As a C# developer, I find that this gives us a fluent way to document the code (at the source) while the IDE makes it easier for the developer to discover the comments. Even for local variables, when we need to know more the convention is to right click and goto the definition of the variable as the first destination for documentation.
It is undoubtably a key productivity feature of Visual Studio and one of the reasons that some people switch over to .Net from java.
It is great for maintenance and team productivity because this is a standard feature of the language that is supported in all the major IDEs so old and new developers coming into a project should all be familiar with this, you do not need to develop or follow a separate standard for a given project or dev team.
The feature itself does not however help with speed-reading of the code because you have to move the mouse to hover over the variable. To improve reading efficiency, you should implement more descriptive names but don't go over the top.
- Or if you think you need to, just add a comment in the code!
Apps Hungarian is not a bad style of convention if you feel the need to overshare using concise notation, but do not include the actual type of the variable in the name, that is largely irrelevant to understanding the context and intent of the code.