Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have just had a not let me sleep doubt about how to name a local variable which stores the text entered by an user (in a text box).
Should I name it 'enteredText' or 'textEntered'?
My main concern is about what comes first? participleSubject or subjectParticiple.
There are some accepted patterns as in events, where it is always onSubjectVerb, e.g. onItemClick ...
I am not sure which is the styling rule for my case (entering text in a TextBox'
I have made some searches on different code repositories and both names are used?
Any idea?
Thanks!
Miguel Ángel
This problem is one of the two hardest problems in computer science, naming things. I think that both are equally non descriptive of what the text that has been entered describes.
For example: what does this text field provide the use the ability to enter? Their name? Then call it userName
More of a matter of taste, I think.
Anyway for me it is a matter of context: if I'm writing a complex class or method with lots of variables and where e.g. there's text entered, text computed and text fixed (i.e. a label), I tend to name them textEntered, textComputed and textFixed, so when I need to access some kind of text the IDE auto completion features easily show me all texts available.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Lets say I have class Report and I want to add a functionality printReport(...) and shouldBePrinted(...). Printing it requires GeneralPrinter and LanguageTranslator which are given from outside. Furthermore, I should add members to make the shouldBePrintable method more optimized.
The way I see it there are three ways of doing it:
The simplest is to just add the members and functions to the Report class.
Create PrintableReport which extends Report and adds those members and functions.
Use the decorator pattern to add the needed functionality. (Not sure about that one. Please correct me if this is not the correct way to use a decorator.)
Am I missing some and which is the correct method to do it?
Consider: Separation of concerns
At a HIGH level...
While it's not clear exactly what role Report fills, one might surmise it represents information organized in some fashion.
Rendering is a separate concern. Often you'll want multiple ways to render: Generate PDF, HTML, XML, and/or print (postscript, other...).
So, perhaps you have multiple classes to work with Report, GeneralPrinter, ReportPrinter, ...
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm not sure is this right place to ask so correct me if I'm wrong.
The case is that:
one category has one code
we want to get list of codes for multiple categories
Which version is correct and why?
getCategoriesCodes()
or
getCategoryCodes()
I see this problem from two points of view, one is the English grammar, and the second one is the clean code and code meaningful naming.
Please give me your opinion which method name is better and add note is English you native language.
As both a native English speaker and a Java programmer: getCategoryCodes() is preferable. getCategoriesCodes() implies to me that I am getting multiple codes for each category, or that the codes relate to the collection of categories, rather than a code for each category.
As an example from "real" English: a car has one driver; you would refer to the drivers of many cars as "car drivers", not "cars drivers".
I would side with the clean code and meaningful naming. Nobody will judge your English in your code and also looking at the code in a month or a year will make it easier to understand if its worded correctly
There is no harm in giving names grammatical correct provided it is readable and understandable and not become very long because long names are difficult to understand.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I recently started a project in Java, that contains a class called System. This class (Luckily) contains methods for output management, so in the rare cases where I need to use the System. methods (Or the System object in general) I just reference it as java.lang.System.. I believe that this could be looked down upon, as System could be looked at as a reserved name. I currently am in the beginning stages of this program, and could change it accordingly quickly, as there are little calls to the class itself.
While it's not illegal, you don't want to do this. If I were the next person working on your code, the first thing I would do is try to remove "java.lang" from "java.lang.System" and then get miffed when it wouldn't compile.
The idea is to go toward brevity and only write what you need to write, while making sense of it all for the next person. It's more an art than a science.
You could always name it something like ProjectnamehereSystem or OutputManager or something to that effect.
I would not create something so similarly named as an important class. While everything is easy to edit, you may be able to keep up with all the changes you are making.
But when the project evolves things will get messy and complex. I would suggest naming it something else that can be easily distinguished.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i am having some issues with this question for my homework and was wondering if anyone has any ideas or insights to the answer really struggling ,,,,
You are to amend the program you created last week, this time however the program will ask you to
type the names that need to be stored. Once this is complete the program will display the names in
alphabetical order and display the number of characters for each name and the number of vowels
each name has.
Since this is homework, I'll give you a hint. If you've studied the Java Collections, you can stored the names in alphabetical order. If you've not got to collections yet, the you simply save them off as Strings as they come in.
When it's time to display them in alphabetical order you could:
- sort them before you display them
- or brute force it. Loop thru your storage of names and display all the A's. Then loop thru picking up the B's.
As for counting vowels, look at the Java documentation for the methods that are on the String class. Hint - look for methods that return an "int".
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm working on my first big project and one thing I need to do is create a log of all the ships in a game and all their stats, their name, class etc... There must be at least over 100 ships. I thought about using a Hashmap, but I would need more than one value per key. I thought about doing a bunch of string arrays, but I think that would take too much memory. Should I read the values in from a .txt file? Any suggestions would be greatly appreciated, and thank you for your time. :D
What is the unique identifier for a ship? You can simply create a hashmap using that unique identifier as the key and the ship instance as the value. In addition, there is nothing preventing you from using a MultiMap to store a collection of values at each key if that makes semantic sense. But this question is rather poorly defined with respect to what you actually want this 'log' to do.