We get asked, on a fairly regular basis, to review code in a project (that we didn’t write) and make recommendations on how to improve it. One of the things that annoys me to no end when I review OPC (Other People’s Code) projects is when developers use the default control names that Real Studio provides in the Layout Editors.
The default naming convention used by Real Studio is the baseline minimum. In my opinion, you have one instance where using the default name is acceptable and that’s with Labels. And that’s ONLY if you never access the label in your code. Really, that’s it. Everything else should be named so that I (and I really mean you too) can read your code at a glance.
Real Studio doesn’t help us out very much on this one. Once you’ve placed a control on the Window/Page it should, in my opinion, automatically have the control name selected so that all I’d have to do is type in the name I want and then move on. It doesn’t despite my Feedback items from many moons ago. At one point I was told it’s not going to be possible in the current version of the IDE. I don’t remember by whom, or when, but I can take that at face value because the new IDE is coming soon. Hopefully they don’t force the same bad practices upon us again.
Yeah, I know I’m being anal about this, but if I’m looking at your code and I’m trying to distinguish between TextField1, TextField2, and TextField3 and have to refer back to the layout to tell what each one is, that will be my first suggestion to you. I’m not a mind reader and, let’s be honest, I’m as lazy a programmer as I can get away with. Real Studio makes me use the mouse too much as it is so you’ll be better off making your own life easier too. After all, isn’t txtFirstName, txtLastName, and txtCity much more intuitive then the original names?
We have our own coding standards document that each new developer gets when they start. It has the list of prefixes we use for our controls (and variables but that’s a different post). So not only does it tell me what it does (or represents) it tells me what control type it is. So btnSave, lstNames, chkEnabled, and rbOpenAtStart is inherently clear when I see them accessed in code because I can tell control type and function at a glance without seeing the layout editor.
We have dozens of internal projects. We have about a half dozen consulting projects at any given time. The very last thing I want to do is look at a layout to figure it out. My time is too valuable to muck around with the layout editor. Your time should be that way too. Remember, you’re coding for clarity not just for now, or five months from now, but for five years from now. You really think you’ll remember what TextField1 is going to be by next Friday? Do yourself a favor and name your controls something meaningful.
Heck, I don’t even care what your naming conventions are. Just get some and use them – consistently. You’ll be happy you did. If you’ve watched any of my training videos you’ll realize that I take great pains to name controls. I do this for everything. This is one of the shames of the Real Studio example projects because many of them use the default names thus giving people new to the language the impression that this is ‘best practices’. Thankfully this is changing a bit but it won’t be too soon for me. I’m tired of making this particular recommendation on OPC projects.
What about you? Do you feel this is a big deal or am I just having a really bad day? What things so you wish Real Studio did better to help you write better code?