Naming and grammar: getResultsCount or getResultCount? - naming

When writing API methods that count something I always lose a tremendous amount of time thinking about how to write the thing that is being counted.
Singular or plural?
For instance, how would you name a function that counts results?
getResultsCount or getResultCount ?
This might sound silly, plural sounds more logical, but since both forms are found in the wild (google gives ~4800 results for "getResultCount" and ~4600 for "getResultsCount"), I'm hesitating and it bothers me.
Disclaimer: I'm not a native English speaker :)
Is there only one grammatically correct form or is it a matter of taste?

You should naming it basically for what it will do, if getResultsCount make mores sense than getResultCount, name it getResultsCount, else, name it getResultCount.
Its not that hard, Ill you have to do is give name that sweets better accordinling to the what it will do.
I suggest you read the book Clean Code written by Robert C. Martin, it really give good tips about naming.

Related

'Or' not working with strings in if conditional after user input

So, I'm a noob, and after 2 hours of searching online, I can't find an example of my failed code ANYWHERE, nor can I find answers related to my specific dilemma, which is surprising since it seems like it would be a fairly common conceptual mistake.
Here's my code:
name = input('Who are you?')
if name == "Mike" or "mike":
print('Hi',name,', nice to see you!')
else:
print("I don't know you.")
All I want the program to do is print the 'Hi', name... statement if the user inputs Mike or mike. I'm not wanting to just change the case, but in the future I'd like to use 'Mike' or 'Susie' (or something like that).
Right now it's always printing the 'Hi', name... statement no matter what I input. If I delete one of the names, then it works.
Can someone tell me:
a) Why it doesn't work the way I tried coding this, and
b) What would be the easiest and/or most efficient way to code this, especially if I want to increase the number of inputs that are accepted?
Thanks all,
You did not give a programming language, but your problem is universal across all languages.
You are trying to cram a colloqial sentence into computer logic and it fails. The computer does not understand your human shortcuts, it needs it spelled out:
This is what you would say to another human:
if they are Mike OR Susie
This is what you mean by that:
if their name is Mike OR their name is Susie
And this is exactly what you need to tell the computer:
if name == "Mike" OR name == "Susie"
Please note that a good language/IDE combination with a good confiuration will throw you a lot of warnings and errors when you compile, it won't even let you run your colloqial human logic. If yours does not, you need to tune it up to assist you better and if it cannot be tuned up, you may want to think about using a better IDE or a better language in general.

(Probably) A Simple Command - Excel

I just joined recently and am really excited to dive into the world of programming. There is still a ton of stuff I don't know, but I'm very proud of myself because I feel like I'm making headway into programming, whereas I used to have a mental block before. I've always been an infrastructure type of gal. But anyway --
I am creating an excel spreadsheet for my new budget. Here is a screencap of my problem (According to rules, new user can't attach images):
http://i66.tinypic.com/hx53zm.png
So this is what I want it to do, logically speaking: Stay blank (B38) until something is entered. Do (B7-B14-B36) if all the fields have something in them. Otherwise, just subtract whatever's in either B14 and/or B36 from B7.
I'm sure it's really simple -- I just lack the knowledge since I'm new. I have been playing around with this for a few days and searching on Google, and I can't figure out how to make it work for my spreadsheet. I have tried the CountA, Count, If, Isblank statements... and just can't get it to go.
This isn't really important to anything in my life, it's just something I'm making for myself to keep my financials in order -- AND to give me practice with some coding.
Thank you for any help you can give me!
Chris
If I understand you correctly, you will want to add the following to B38
=IF(B7 <> ""; B7-B14-B36; "")
Depending on your version of Excel, you may need to replace the ; with ,

Suggestions wanted: What should I name a class that represents a real-life "event"?

I need to define a class that represents a real-life event -- like a "movie premier", "party", etc. I will be creating a set of database objects to store the data for each event and define relationships with other data we have (e.g. venue, people, etc.).
The word "event" has a different meaning in the context of software, so I'd like to name the class something other than "event".
Any ideas on another name?
This related post asks a similar question, but I think all of the suggestions lack creativity -- basically #event, the case-sensitive name Event or use the old-school naming convention CEvent. Technically good solutions, but they don't help when discussing the data objects with peers (my speech and listening abilities are case-insensitive) and don't convey any information on how the class is not an event in the traditional use of the term.
One option would be CalendarEvent, to make it obvious that this is a real-world event tied to a given date.
Activity come to mind.
How about Happening or Occasion?
Normally I'd recommend function, but it too has specific meanings in the context of software. ;)
Occasion might be a good synonym.
The thesaurus lists the following as synonyms of the word event:
accident, act, action, advent,
adventure, affair, appearance,
business, calamity, case, catastrophe,
celebration, ceremony, chance,
circumstance, coincidence,
conjuncture, crisis, deed,
development, emergency, episode,
experience, exploit, fact, function,
holiday, incident, juncture, marvel,
matter, milestone, miracle,
misfortune, mishap, mistake, occasion,
occurrence, pass, phase, phenomenon,
predicament, proceeding, shift,
situation, story, thing*, tide,
transaction, triumph, turn, wonder
Surely one of them would suffice... if not, you can prepend or wrap the word event to make it a non-keyword. Something like #event or [event] although, I have to say that I don't personally like this practice even though it is syntactically permissable.
You could call it a 'Rendezvous'. You could also just make up a word. If this is a key concept in your domain you could abbreviate one of the other suggested names. Things like:
CalenderEvent becomes Calvent
SocialEvent becomes Socent
RealWorldEvent becomes Revent
HumanActivity becomes HAct
Those quick examples might be terrible examples but they are short, don't collide with language or library names, and will become real meaningful words for you and your coworkers very quickly if you work with them frequently.
Perhaps "Affair" or "Advent" -- you could also check the thesaurus:
http://thesaurus.reference.com/browse/event
Entry or EventEntry are probably what I would go with.
I can appreciate you want to avoid confusion with events in the programming sense, but my take on it is that maybe you should go with the most obvious name; program to your domain, and things stay readable and easier to design and maintain.

Determining what a word "is" - categorizing a token

I'm writing a bridge between the user and a search engine, not a search engine. Part of my value added will be inferring the intent of a query. The intent of a tracking number, stock symbol, or address is fairly obvious. If I can categorise a query, then I can decide if the user even needs to see search results. Of course, if I cannot, then they will see search results. I am currently designing this inference engine.
I'm writing a parser; it should take any given token and assign it a category. Here are some theoretical English examples:
"denver" is a USCITY and a PLACENAME
"aapl" is a NASDAQSYMBOL and a STOCKTICKERSYMBOL
"555 555 5555" is a USPHONENUMBER
I know that each of these cases will most likely require specific handling, however I'm not sure where to start.
Ideally I'd end up with something simple like:
queryCategory = magicCategoryFinder( query )
>print queryCategory
>"SOMECATEGORY or a list"
Natural language parsing is a complicated topic. One of the problems here is that determining what a word is depends on context and implied knowledge. Also, you're not so much interested in words as you are in groups of words. Consider, "New York City" is a place but its three words, two of which (new and city) have other meanings.
also you have to consider ambiguity, which is once again where context and implied knowledge comes in. For example, JAVA is (or was) a stock symbol for Sun Microsystems. It's also a programming language, a place and has meaning associated with coffee. How do you classify it? You'd need to know the context in which it was used.
And if you can solve that problem reliably you can make yourself very wealthy.
What's all this in aid of anyway?
To learn about "tagging" (the term of art for what you're trying to do), I suggest playing around with NLTK's tag module. More generally, NLTK, the Natural Language ToolKit, is an excellent toolkit (based on the Python programming language) for experimentation and learning in the field of Natural Language Processing (whether it's suitable for a given production application may be a different issue, esp. if said application requires very high speed processing on large volumes of data -- but, you have to walk before you can run!-).
You're bumping up against one of the hardest problems in computer science today... determining semantics from english context. This is the classic text mining problem and get into some very advanced topics. I thiink I would suggest thinking more about you're problem and see if you can a) go without categorization or b) perhaps utilize structural info such as document position or something to give you a hint (is either a city or placename or an undetermined) and maybe some lookup tables to help. ie stock symbols are pretty easy to create a pretty full lookup for. You might consider downloading CIA world factbook for a lookup of cities... etc.
As others have already pointed out, this is an exceptionally difficult task. The classic test is a pair of sentences:Time flies like an arrow.Fruit flies like a bananna.
In the first sentence, "flies" is a verb. In the second, it's part of a noun. In the first, "like" is an adverb, but in the second it's a verb. The context doesn't make this particularly easy to sort out either -- there's no obvious difference between "Time" and "Fruit" (both normally nouns). Likewise, "arrow" and "bananna" are both normally nouns.
It can be done -- but it really is decidedly non-trivial.
Although it might not help you much with disambiguation, you could use Cyc. It's a huge database of what things are that's intended to be used in AI applications (though I haven't heard any success stories).

What is the meaning of "I cosay"?

Search the web for the phrase "I cosay". I run across this phrase being used from time to time by individuals in tech forums, but for the life of me, I cannot figure out what it means or how it makes sense in the context of the conversations where it is used.
Am I just way behind the times? New slang?
As far as I can tell from the contexts Google pulls up, it is a very poorly machine-translated form of "codigo". "digo" or some variant is "I say", so it forms it as "I cosay" when it really shouldn't be translated at all. Roughly translated it should probably be "code" or "encoding".
It's pig latin for Psycho.
Without context, I'll have to say a cosay is the counter-say in the same vein that cosine is a counter to sine.
from the context of usage it looks like slang for agreement - you say X and I cosay X - possibly invented by non-native english speakers - but that does not cover all of the contexts of usage...
In french from Quebec (not France) it means : "I do not understand what you are talking about, can you repeat?" but it's a very low level of language... nothing official and shouldn't be used ... often kid use that type of expression...

Resources