Quicker IDE Code Suggestion Without Case Sensitivity
It is amazing how much time we can waste by not creating and sticking to a style of coding. A lot of new young web designers don’t realise that case sensitvity can be activated for code suggestion tools. Some won’t know code suggestion exists of an IDE does not activate it automatically. If your like me, you know about it but you don’t want to use case sensitivity. In that case there are basic things we can do to help code suggestion tools quickly offer the correct match.
Naming Constants
If you want to make life easier on yourself when it comes to trying to find functions and constants plus telling them apart from each other quickly then continue to read about my own approach. In some cases you may be writing script that will end up in an environment with other code not written by yourself. What if someone creates the exact same named constant? Well I think we know the problems it can cause and not only is it easy to avoid but we can almost avoid it without a doubt by sticking to a little rule.
Here is my constant writing rule…
- My constant always begins with an abbreviation that identifies me or my company: WTG
- I then use underscore and so end up with: WTG_
- Then I add the abbreviation for my project follow by another underscore just to help it stand out: WTG_ECI_
- I then finish with the term indicating the constants purposes: WTG_ECI_LANGUAGE
Naming Functions
I use the same approach as above to name my functions but there is a change that helps a lot of IDE code suggestion tools find existing matches to what your typing.
Here is my function writing rule…
- My function always begins with my abbreviation but I also add the projects abbreviation: wtgeci
- Then I use an underscore and what I have is a standard unique value to help prevent function conflicts with other applications: wtgeci_
- Then we finish the function: wtgeci_language()
So Whats The Big Advantage?
Right now I’m NetBeans IDE, I’ve not long switched from using Zend Studio for a year and before that I was on Dreamweaver for a year. There are reason for that I will not go into. An IDE software allows us to activate code suggestion, you know that thing that displays a long list of your previously used values, narrowing it down to the closest match based on what you’ve already typed. This helps us avoid typing it out again and more importantly we get it right.
If you follow my naming rules and you type your abbreviation then add an underscore, the IDE will instantly remove all functions from the list! If for example I type wtg the list is the same as typing WTG unless you activate the setting (if it exists in the IDE) for case sensitivity. My post is about not using case sensitivity and my approach allows me to instantly hide all functions in the code suggestion list by typing WTG_ or I can hide all consants by typing wtgeci_, two very easy to remember values especially if you continue to use the approach for all projects.
Using This Approach Further To Group Functions
You can create more rules that have the same effect, even if you use case sensitivity your appended or pre-pended naming values can help you to locate the correct function or constant or variable especially global variables. You can identify a group of functions by adding a term to each functions within that group, something we’ll usually do naturally anyway. You might not considering adding a single a single letter, maybe your application simply isn’t big enough to need such an approach but if you are working on a large application, you can group functions by the area of the application they work within i.e. wtgeci_a_myfunction(), wtgeci_a_anotherfunction() and wtgeci_a_finalfunction(). Lets say these functions with “a” in them are functions involved in building the interface, generating dynamic forms or generating the script for jQuery UI etc. They are not processing functions, functions which update the database or make any type of change. We can then use the exact same function names but change the “a” to a “b” wtgeci_b_myfunction(), wtgeci_b_anotherfunction() and wtgeci_b_finalfunction(). In my application these functions are used to process form submissions. So wtgeci_a_myfunction() is used to build a complex form, wtgeci_b_myfunction() is used to process/validate the submission and occasionally I will take it a step further creating wtgeci_c_myfunction() which will make any required changes or final output to the user providing the “b” function validated all values else outputted warnings about invalid form input values.
The advantage we have in the function examples above is being able to type wtgeci_?_myfunction() and change ? to a,b or c very quickly. Allowing us to use the tools in the IDE to check on each related function quickly. You can organise your code in this way and if you find an approach you enjoy using you should notice a slight improvement in your development speed. When I’m developing a new application from scratch I type the function name then change the middle letter to get a quick reminder if I have finished the functions for the related form or for the related $_GET process and so on. This is just a great way to navigate between related functions.