Really long class/variable/property/method names - naming-conventions

Some friends and colleagues of mine have a little running contest to find or write the longest class/variable/property/method names possible. Keep in mind, we try to be good boys and girls and keep the naming intelligible and concise, while still explaining what the thing does via its name.
Sometimes it just doesn't happen though. Have you run in to this? I'd just like to see what's out there. (Maybe my friends and I aren't as crazy as we think)
Note: I'm not looking for bad naming. That's already here. I'm looking for good naming that just got a little long.

This isn't a class name but an enum, but it's a lot longer:
VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeStateVmDirectPathGen2InactiveReasonOther
from the VMware vSphere API. Google for it and you'll find the online documentation.

It isn't really long but my favorite variable name ever was to indicate that a user had opted in to receive email.
User.IsSpammable

I find it's nice to have long test names which describe the test. For instance:
testMapWithOneEntryAllowsDifferentEntryPreservingFirst
testMapWithOneEntryAllowsDuplicateEntryOverwritingFirst
(These are just examples off the top of my head... you get the idea though.)

org.aspectj.weaver.patterns;
public class HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor {
boolean ohYesItHas = false;
public boolean wellHasItThen/*?*/() {
return ohYesItHas;
}
... more methods...
}

Some times ago, I had a problem with Hibernate.
I got a NullPointerException in the method called findIntendedAliasedFromElementBasedOnCrazyJPARequirements !

protected virtual OcrBarcodeSymbologies GetSupportedBarcodeSymbologies() { }

The excellent GTK+ library "suffers" from this. It has very neatly named functions, but since the main API is C, and GTK+ is very object-oriented, it must encode class names in the functions name. The constructor for class X is X_new(), and so on. This leads to beaties such as gtk_recent_chooser_widget_new_for_manager().
I'm sure there are even longer function names in there, this was just one that I found quickly. :)

Long variable names don't bother me as long as there's not an obvious more concise name and the naming is sane. For instance, in Kamaelia, there's a class type named this:
threadedadaptivecommscomponent

A naming convention I've seen, years before fluent became en vogue
public DataSet SelectAllUsersWhereDobIsGreaterThan1980AndIsMaleOrderByNameAndAge()

Check out Apple's documentation. They're kings at that. Very descriptive, but sometimes miles long. A couple of examples from the NSString class:
NSString.completePathInfoString:caseSensitive:matchesToArray:filterType
NSString.stringByAddingPercentEscapesUsingEncoding
My favourite in the Microsoft world: SetProcessWorkingSetSize

bool instrumentAreaDockWidgetVisibilityFollowsChildPresence;

In the apple mail app:
_synchronouslyTellServicesToRegisterAndSync()
In a app I wrote:
User.CanViewRestrictedItems()
I an app a colleague wrote:
Profile.DisplayMyDraftOrPendingProfile()
Profile.DisplayMyApprovedProfile()
Just to get started.
new:
A foreign key constraint name:
constraint ReportCompanyReportTemplateIDVersionID_ReportTemplateVersionReportTemplateIDVersionIDFk foreign key (ReportTemplateID, VersionID) references customer_ReportTemplateVersion (ReportTemplateID, VersionID)

get the js items that will be retrieved and if page should display recommendations.

Related

How do I set up Protobuf for my VB.net application?

So, this may seem very elementary for you guys but I am officially stumped. I am trying to save some data in my application to a file using protobuf (suggested to me by some peers) but I can't seem to find any documentation for it and what I can find always gives me some weird error. I have an array declared as follows:
Private Terrain(,,) As TiledTerrain
The TiledTerrain class looks like this:
Public Class TiledTerrain
Public X As Integer
Public Y As Integer
Public Texture_X As Integer
Public Texture_Y As Integer
End Class
Pretty dog-on simple right? Well, I can't seem to figure out how to save my Terrain array to a file using Protobuf?
The Terrain array is just a simple 3 dimensional array (about 100x100x2). Each cell of the array may or may not actually contain a value (TiledTerrain) and if it doesn't it will contain "Nothing".
Can anybody explain to me in full on how I should go about doing this? I've currently referenced protobuf-net.dll and protobuf-net.Extensions.dll because I don't really know which to use...
Thanks for any help!
-A Moron Among Geniuses :)
first read Getting Started which describes the simplest scenario, using attributes. VB has slightly different syntax for attributes, which you are probably more familiar with than me - but the concept is the same.
There are alternatives, note:
in v2 the model can be configured entirey at runtime if you want, without the need for any attributes
if the type looks like an obvious "tuple" (including, importantly, a constructor that takes a parameter that matches every public member), it will use the constructor order to infer a contract
There is a problem though; protobuf-net does not currently support multi-dimensional arrays. It can of course be added, but as with all features: it doesn't exist until it gets written. The reason this isn't supported directly is that the underlying protobuf specification (by Google) does not support this. It would work if flattened into a vector (1-dimensional zero-based array). If you want help with an example, let me know.

Any advantage to prefixing Enum values?

In this post Jon Skeet pointed out that the following code should be changed to conform with the .NET naming conventions. Doing that would also decrease the amount of noise in the code.
Enum enUtilityTypeDetailStudentEntryWorkflow As Integer
enUTDSEW_Default = 379
enUTDSEW_ApplicantRecordBook = 380
End Enum
I must admit, I was pretty much like a sheep and was following what others have done before me. I thought the prefix did not look right and then to have it twice did not make sense either.
After looking at a couple of .NET Framework examples, it looks like this would be closer to the standard.
Enum StudentEntryWorkflow As Integer
Default = 379
ApplicantRecordBook = 380
End Enum
Am I on the mark with using these names?
Any other suggestions or comments in general?
Where I work we also use a prefix for enums (E in our case), and I must say that I like it. It makes it very easy to spot an Enum and differentiate it from a class or variable. Here's an example from our codebase:
myJob.Status = EJobStatus.Completed
Here we can easily see that the status that's been assigned to the job is the value "Completed" from the enum "EJobStatus".
My personal preference aside, if you want to follow the .NET naming conventions, then there is no prefix to enums. But the most important of all is to always follow the same conventions in a given code base.
Edit: I just saw that you also prefix the actual enum values, we don't do that though. We always refer enums this way ESomeEnum.SomeValue. In that case it's not useful to prefix the actual enum value. Also, I don't think it's a good idea to use the same prefix for the enum name and the enum values, because they're not the same thing.
I don't know about standard, but using Hungarian notation on enums and enum values is not something I have seen before.
Your second example is closer to the kind of code I normally see, so in that respect, yes, it is more standard.
See section 8.2.3 on this guideline - pascal casing and no prefix/postfix.
Guideline 16 of Section 2.1 of Lance Hunt's C# coding standards also says to avoid prefixes and postfixes.
I would say this is pretty universal - the point of having enums it to aid readability. Using prefixes and postfixed reduces readability and thus is pretty universally discouraged.
In VB.net, I don't believe you can refer to an enum value without prefacing it with the name of the enum, so it's completely redundant to "prefix" the enum value name with anything.
ie, you couldn't use
dim x = enUTDSEW_Default
even if you wanted to, you'd have to use:
dim x = enUtilityTypeDetailStudentEntryWorkflow.enUTDSEW_Default
which is just silly.
The enum prefix probably came from a C++ programmer. In C++ the enum name isn't part of the value's fully qualified name:
class Class
{
public:
enum Enum
{
Value1,
Value2
};
};
// Yes
Class::Enum e = Class::Value1
// No
Class::Enum e = Class::Enum::Value1
but .NET syntax calls for the second version. So there's no benefit to a redundant value name.
I do it in C# to avoid the compiler issue of having the property name the same as its (enum) type, which I've found I'd liked to do in the past.

What is the antonym of encapsulation?

Using online dictionary tools doesn't really help. I think the way encapsulate is use in computer science doesn't exactly match its meaning in plain English.
What is the antonym of computer science's version of encaspulate? More specifically, what is an antonym for encapsulate that would work as a function name.
Why should I care? Here's my motivation:
// A class with a private member variable;
class Private
{
public:
// Test will be able to access Private's private members;
class Test;
private:
int i;
}
// Make Test exactly like Private
class Private::Test : public Private
{
public:
// Make Private's copy of i available publicly in Test
using Private::i;
};
// A convenience function to quickly break encapsulation on a class to be tested.
// I don't have good name for what it does
Private::Test& foo( Private& p )
{ return *reinterpret_cast<Private::Test*>(&p); } // power cast
void unit_test()
{
Private p;
// using the function quickly grab access to p's internals.
// obviously it would be evil to use this anywhere except in unit tests.
assert( foo(p).i == 42 );
}
The antonym is "C".
Ok, just kidding. (Sort of.)
The best terms I can come up with are "expose" and "violate".
The purpose behind encapsulation is to hide/cover/protect. The antonym would be reveal/expose/make public.
How about Decapsulation..
Though it aint a computer science term, but in medical science, Surgical removal of a capsule or enveloping membrane.. Check out here..
"Removing/Breaking encapsulation" is about the closest thing I've seen, honestly.
If you think of the word in the English sense, to encapsulate means to enclose within something. But in the CS sense, there's this concept of protection levels and it looks like you want to imply circumventing the access levels as well, so something like "extraction" doesn't really convey the meaning you're looking for.
But if you just think of it in terms of what the access levels are, it looks like you're making something public so, how about "publicizing"?
This is not such a simple question - Scott Meyers had an interesting article to demonstrate some of the nuances around encapsulation here.
I'll start with the punchline: If
you're writing a function that can be
implemented as either a member or as a
non-friend non-member, you should
prefer to implement it as a non-member
function. That decision increases
class encapsulation. When you think
encapsulation, you should think
non-member functions.
How about "Bad Idea"?
The true antonym of "Encapsulation" is "Global State".
The general opposite of encapsulation is coupling and we often talk about systems that are tightly coupled or loosely coupled.
The reason you'd want components to be encapsulated is because it makes it easier to reason about how they work.
Take the analogy of trains: the consequence of coupling the railcars is that the driver must consider the characteristics (inertia, length) of the entire train.
Obviously, though, we couple systems because we need them to work together.
Inverted encapsulation and data structures
There's another term that I've been digging for, which is how I came across this question, that refers to a non-standard style of data structures.
The standard style of encapsulation is exemplified by Java's LinkedList; the actual nodes of the list are designed to be inaccessible to the consumer. The theory is that this is an implementation detail and can change to improve performance, while existing code will continue to run.
Another style is the classic functional cons-list. This is a singly linked list, and the idea is that it's so simple that there's nothing to improve about the data structure, e.g.
data [a] = [] | a : [a] deriving (Eq, Ord)
-- Haskellers then work directly with the list
-- There's nothing to hide because it's so simple
typicalHaskell :: [a] -> b
typicalHaskell [] = emptyValue
typicalHaskell h : t = h `doAThing` (typicalHaskell t)
That's the definition from Haskell's standard prelude though the report notes that isn't valid Haskell syntax, and in practice [a] is defined in the guts of the compiler.
Then there's what I'm calling an "inverted" data structure, but I'm still looking for the correct term. This is, I think, really the opposite of encapsulation.
A good example of this is Python's heapq module. The data structure here is a binary heap, but there isn't a Heap class. Rather, you get a collection of functions that operate on generic Python lists and you're responsible for using those methods correctly to ensure the heap invariants are maintained.
How about "spaghetti"?

Destructor or Deconstructor with regards to OOP?

In my daily life and while reading books I've seen the term destructor as well as deconstructor.
But what is the correct name for this method?
It is destructor used to cleanup the stuff when the object is about to die. It is called automatically if specified when object is going to be removed/die.
More Info:
http://en.wikipedia.org/wiki/Destructor_%28computer_science%29
Destructor if you are refering to OOP. Deconstructor when talking about
World of Warcraft ;-).
Destructor is the most common term (deconstructor sounds like local usage: I like it in a way, since it points out a symmetry with constructors).
But these things are to some extent language-specific, since different OO languagers have different models for the lifecycle of instances. Take C#, for instance, where instead of destructors you have finalizers, which have weak execution guarantees, supplemented by the language-supported Dispose() pattern which provides determinacy.
As others has explained already, a destructor is used to clean up an object.
There is a new feature in C# 7, which can be referred to as a deconstructor:
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public void Deconstruct(out string firstName, out string lastName)
{
firstName = FirstName;
lastName = LastName;
}
}
var person = new Person { FirstName = "John", LastName = "Smith" };
var (localFirstName, localLastName) = person;
The more common names for this feature are deconstruct method or simply deconstruction but I found at least one instance on the official msdn blog referring to it as a deconstructor (emphasis mine):
It will be a common pattern to have constructors and deconstructors be “symmetric” in this way.
"Destructor" is indeed the correct term.
I have seen "deconstructor" in older books, and it appears that there was debate for a while over the correct term, but destructor appears to have won out.
As for the flippant answers about what wiki or WoW says about deconstruction: try looking up "destructor" in a standard dictionary. Apparently, it's a device for destroying an off-course airborne missile or launch vehicle.
Destruct = Destroy
Deconstruct = Decompose (Reverse compose into pieces)
Put -tor then it's the executer of the verb.
So it's depend on the context you trying to achieve.
I still remember the lecture that introduced concepts in Haskell when I first heard of the word "deconstructor". I first was confused because I thought of destructors but as it quickly turned out, they are different concepts. Haskell has no destructors but deconstructors. They are used to retrieve single data member fields that a structured value contains. They are basically member accessors but as functions.
I actually wondered about the word because I practically never found it elsewhere. Here I found an answer:
https://softwareengineering.stackexchange.com/questions/168650/whats-the-proper-term-for-a-function-inverse-to-a-constructor-to-unwrap-a-val
Decomposer oder destructuring could be a good equivalent term and "destructuring" really is something that I commonly have heard of.

how do you call this anti-pattern?

In the database you have a table with a bit field, let call that field Active
In the application you have a variable boolean, let call it NotActive
Everytime you get the field from the table, in the application you have switch the meaning of the variable.
NotActive = !mytable.active;
Another example would be a bit field in the database named Enable__yes__no and in the code you do
control.enabled = !mytable.Enable_yes_no
best practice would be to keep the same name and the same meaning, but the pattern above, how to you call that?
I wouldn't name boolean variables with a negative prefix.
Name the variable IsActive or Active, naming it NotActive is double negation.
Edit/Clarification:
If you need to check if the thing is active, you need a double negation:
If (!NotActive) { DoSomething() }
Positive boolean Variable names are much easier to understand:
If (isActive) { DoSomething() }
Obfuscation by design?
Backward compatibility with existing databases?
It's widely known as the "not-not-negative spaghetti confusion pattern" and was first mentioned 1972. ;-) SCNR
I think the problem here is in the architecture, not in the specific naming of the data. For instance, if you used an entity framework, then your entity for this table could declare a property called InActive, and it could use the Active column as the datastore. As far as the outside world is concerned, the translation back and forth is transparent.