Should I prefix my variable names for components in GUI code? - user-interface

Some coding books mention that we should not prefix the type in the name, since current IDEs are able to make these visible and clear. I completely agree for primitive types but I'm inclined to still prefix my GUI components variable names.
What are the best practices when working with on GUI code regarding GUI component variable naming?
E.g. should I name my
Button btnSubmit
TextField tfName
Checkbox cbActive
or
Button submit
TextField name
Checkbox active

I find that generally, when naming GUI-components, prefixing the variable name with the type of GUI-component simplifies the process of writing code in that when I write code that references them, I don't have to remember the exact name of each component. E.g. often I know that I'm gonna get the text from a specific TextBox, but I don't remember the exact name of it. I start typing TextBox and up in IntelliSense a range of TextBoxes appear, from which I easily can identify the exact one I'm in need of.
Regarding if it's any best practices; It depends on
If your company has any standards, I'd assume they'd be the best practices in this case.
If it's a private project, go with what you feel is the best.
My 0.02$

Related

Store/Associate NSMenuItems along with folder URLs

So I'm new to OO Programming. Coming from a WebDesign Background and having done mostly design work or some more or less intermediate scripting wherever it was needed in my projects. But being eager to learn and still searching for the "right" way ;-) to do things like you guys do. Not what my Script Kiddie Mind tells me :D. So sorry if that is really a super beginner question, but I would rather grasp the "right" concept from the start.
I'm programmatically populating a NSMenu with NSMenuItems based on contents of a folder located in my Documents Directory. I'm iterating through the subfolders of this fellow, getting the URL of each and every one, extracting the folder name by using
let folder = el.URLByDeletingPathExtension?.lastPathComponent
and creating NSMenuItems based on those names
let menuItem = statusMenu.insertItemWithTitle(folder!, action: #selector(StatusMenuController.doFancyStuff), keyEquivalent: "", atIndex:0)"
So far so good. Now how would I store the associated URL along with the MenuItem for later use like manipulating it when the action gets triggered?
By clicking on the item I want an action to be performed, which needs the full folder URL of course. My first idea was to extend NSMenuItem with a new variable called "path" or so. But since there are no stored values allowed in extensions this is a dead end.
How do you real programmers handle such cases? Using a dictionary and storing the Items along with their respective URLs? Could work, or not? But would that be the correct way? Or getting the full url by taking the MenuItems Title and "reattaching" it to the basefolder URL? Which could also work. Or do you hand the URL to the method/action that will get called as an attribute? I would really love to stay away from messy code :) so your pro insights are very much appreciated.
Thank you for your Time!
andy
NSMenuItem has a property representedObject which can be used for that purpose.
From the documentation:
By setting a represented object for a menu item, you make an
association between the menu item and that object. The represented
object functions as a more specific form of tag that allows you to
associate any object, not just an arbitrary integer, with the items in
a menu.
If you want to store more information than just an URL you could also assign a collection object like Array or Dictionary or even a custom class to representedObject.

Resharper "No Suggestions" box

I noticed that Resharper adds "No Suggestion" box on new properties in C# classes. Like this:
This "No Suggestion" box does not add anything to the code, only obstructs lines of code below - and that is an annoyance.
Any way to make Resharper not show this box?
You can edit the prop Live Template and remove the macro associated with the $NAME$ variable of the property.
What ReSharper is trying to do is suggest a name for the property, based on the type. If it's a bool property, there's not much it can suggest, but if it's a complex type, such as Address, then it can suggest a name such as Address. Also, if it's a List<Address>, ReSharper will suggest Addresses or List. So, it can be useful.
However, it isn't terribly helpful to show No suggestions - it might be nicer to just not show anything if the list is empty. I've added a feature request you can vote on and track: RSRP-453668

Joomla 3 Overwrite/Change "Menu Manager: Edit Menu Item"

Like the topic say I want to overwrite/change the "Menu Manager: Edit Menu item" layout. To illustrate my question:
In the picture whiche is shown I want to change the labels: Layout, Option, Integration.... and add some other options to it. How can I do it? Or is this even possible?
In order to change the text, simply use language overrides, google is your friend.
In order to add functionality, let's first of all explain what we're talking about to ensure we're on the same page.
Joomla components have views which can have one or more layouts, i.e.
/components/com_content/views/category/tmpl/ contains two layouts, blog and default.
A layout can additionally contain an .xml manifest (in our case, blog.xml and default.xml) allowing us to create a menu item for the specific view/layout combination. The .xml file contains the parameters that the user will set, you can add your own as well.
When you want to change Joomla, usually there is a way to do so without touching the core, which would be pretty bad, as any Joomla! updates would break your work.
For the view layouts a special feature called template override was developed, which allows you to create an alternative to the view layout in a safe place (under your template folder, in this case your admin template), and this is the most elegant and effective way to achieve your result.
Beware though, you are just creating a layout, most likely you will want to add functionality, if it's complex you might be better off creating a dedicated component to keep the code clean. Or you can just put all the logic in your view, query the database from there. But in this latter case, get paid, and run away. Never answer the phone to the customer again.
A final alternative is to write a system plugin that will manipulate the page markup after it was generated in the event onAfterRender(). This is a simple and good approach if you only want to add a button or make minor changes, but if you do anything more than that, see the above advise about running away.

Best Way to Modify Another Programmer's Navigation

"Change an item in the navigation? Sure I can do that in 15 minutes."
So I am trying to update the navigation on a site that I inherited only to find out that the previous programmer was a college student and was using this site as a project of some sort. Needless to say there are zero comments and the code calls function after function and I just can't follow the logic.
I am looking for a roundabout way to update the navigation. I tried using Dreamweaver to search through all of the files in the site and look for any files that contain the name of the page or the url (hoping to find some sort of included file). There was none. I did file text files that control the main navigation but none for the subnavigation.
There is no database.
If it helps here is the site. http://bit.ly/jbs639
And if you want to look at the interesting text file that is parsed to create the main navigation you can find it here: http://bit.ly/m3erna
Hmmm.... Interesting indeed. You have my sympathy.
One thing that I would look at... The file that gets parsed for the main navigation appears to be a simple delimited file. Sure, the delimiter is a rather unusual +++, but that choice means it avoids conflict with things like commas that might be desirable in the link text. It looks as if the last element indicates what type of resource is being accessed (file or directory, although I don't know what - if any - effect that has on the final output). It also appears that there are similar text files (in the framework/cfg/nav/ folder... which should probably not be generally accessible BTW) for the sub-menus. (E.g. the file stores.txt appears to contain the additional navigation items associated with the stores sub-navigation).
You don't mention which sub-menu you're trying to change. I suspect it is the "About TTO" one, which I can't find an entry for... but I'd look to see if there are any similar navigation text files in the /content/about/ folder.
Good Luck!
Of course it was as simple as a function that reads all of the files in the directory and the name of the file. I guess that in this case there was no shortcut.

How to make derived textbox and toolstriptextbox use same code in Vs2010

I've created a derived WinForm textbox control that knows how to provide a hint (those grayed out words that say things like "Password" or "Enter search here") as well as allowing for the beep on enter to be disabled.
I have two public properties BeepOnEnter, and HintText, a single method - ResetHint and then overrides for the Text property, the OnGotFocus event and the OnKeyPress event.
This code works fine until I have a need for a textbox on a tool strip also known as a ToolStripTextBox.
I'd like to use the same code for both the TextBox AND the ToolStripTextBox. Is there a way minimize/reduce redundancy? I definitely need code that has classes that are derived from TextBox and ToolStripTextBox so the ui designer allows me to drop these new controls on a form or tool strip but can't figure out how to do it in an OO way.
ToolStripTextBox is derived from ToolStripControlHost and TextBox is derived from TextBoxBase and as multiple inheritance is not allowed, you will be best off creating a 3rd utility class and putting all similar functions in it. You can then leverage an instance of this class in your derived controls to get the common functionality you want.

Resources