InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonPainter
javadoc.bugaco.com
javadoc.bugaco.com
InternalFrame InternalFrame
Title Pane,
Internal Frame
Title Pane.
Maximize Button Window,
Not Focused State.
http://stackoverflow.com/questions/1697215/what-is-your-favo...The moderation system on stackoverflow is broken because an unskilled user can gain high reputation by getting upvotes from other unskilled users (I've seen a lot of wrong answers getting up-votes). This means that over time the average level of skill in the people moderating the site drops and you end up with a lower quality of moderation.
Recently I had work on a shell script that used "sed" to make changes in config files. At some point a change only had to happen once a line with a certain string had been seen, so I googled for this situation.
Multiple StackOverflow answers were at the the top of the results as well a several other sites all of them containing incomprehesible examples of line noise. Half the time, the comments on the pages with the aformentioned examples also indicated the solutions didn't work.
So I did a "man sed" looking for examples but it was a pretty short man page which told me to peruse "info sed". Not expecting much I fired up info (which I generally try to avoid: just put your docs in the man page) and to my surprise there was very good and clear documentation on sed which got me to fix my initial problem in 5 minutes in a clear way (well, it did need a comment in the code).
The next time I need to know anything about sed I will check the manual first.
1. Any result on google from StackOverflow is guaranteed to be of the highest quality.
2. I am never ever posting there.
Many questions from the early days of SO were closed because they were too humourous or didn't fit the “needs an objectively correct answer” – this included a lot of such “poll” questions like “What is your favourite ...?”.
http://www.stackprinter.com/export?question=1697215&service=stackoverflow
But you cannot link to individual answers there, sadly. It's the second one, though. InternalFrame InternalFrame
We should be able to make this fit with "Silver Bells."Vogon poetry, to be specific.
About 1000 functions in all (so that's just the globals), of those a hundred have names > 30 characters. There are some real 'gems' in there, consistency - even if self enforced - has a price. The record holder weighs in at 53 characters, it (fortunately) drops off quickly after that.
There are only 2 things hard in programming, cache invalidation, naming things and off by one errors.
Personally I think this name is bad because in spite of the enormous length it still doesn't tell me what it actually does. It just uses a lot of characters to indicate its spot in a hierarchy.
Names like these are what gave rise to jokes like 'Q: What is the spelling of bureaucracy? A: J-a-v-a'. Which of course does a dis-service to java the language and the community behind it.
I can see why they're funny, but you have to realize that when you get out of the trivial program length domain into projects that are 100's of thousands of lines that this problem will sooner or later rear its ugly head. And I have not yet seen any really good solutions.
The things that can help you to extend your runway a bit in this respect are:
- be consistent
- reduce scope wherever possible
- pick short names for primary objects
But even with those rules you'll have a 53 letter name in there somewhere... I'd be very wary of casting stones in situations like these without knowing exactly how the person that picked it originally made their choice. Chances are there were a whole pile of external factors dictating this monstrosity and the guy or girl (or the code generator!) that did it never was happy about it either. Laughing at others that have tackled some problem is easy. Coming up with real solutions and doing a better job of it is a lot harder.1) Most of us never tackle specific problem domains that are very rare
2) Most of us never come up with real world solutions
Most of us these days work on CRUD web-app with only a few who actually go deep into specific problem domains.
Sometimes the problem domains is just that hard. I know there are optimistic developers out there that keep saying "I can simplify this particular problem domains" but here we are in 2012 still writing CRUD web-app.
No. That is just wrong. There is no problem domain that requires the use of very long strings to refer to individual pieces of it. All systems, either statically or dynamically, can be decomposed into smaller pieces who's names are short because they are meaningful within the context of another name.
Or, to put it another way, you get names like this when you statically code a data-structure that should be dynamic.
Then it'd be something like:
RouterMessage.utf8_xml_header
or shorter if you decided on utf8 across the board.I can only imagine the chaos if you start encoding a mixture of Latin-1 and UTF-8 headers :)
1. Static typing can help in reducing the function name.
2. Programming Languages give us means of combinations and abstractions in order to avoid that exact problem.
For example:
class RMG_Serialize inherits Serializor:
router_msg_header rmg
xml_utf8 utf8() {
...
super(this.rmg)
...
}
}The example is not perfect, the function is not exactly globally visible, but I could argue that instanciation of the class is available globally. Or you could get by, by making it static. Also, it's true that I'm adding more characters than any other function name, but no single word I wrote has more than 13 character keeping it easy to read. Every subsequent call to this function will be nothing more than `RMG_Serialize().utf8()`.
Imho, if you feel you're forced to give this kind of name to your variables, there's something wrong either with the design or with the specs.
The choice of programming language counts as well. I mentioned static typing as the obvious example, but isn't a language nothing more than a framework to name your variables?
But I agree with you that maintaining your names short is difficult. I think this has less to do with technical limitations and more to do with project management issues. Generally, I think that a team that understands the value of refactoring (and manage to afford it) will always be better at avoiding this crippling problem.
The other thing is that I prefer symmetry. I would probably write the function to take and return the same thing.
Finally, I might strongly consider writing a generic method that, using reflection, traverses arbitrary data structures and constructs an XML DOM. The caller can do what it needs, e.g. serialize into a string.
If, for some reason, your system requires a specific transformation from a custom data structure into a string, then it belongs in the custom data structure class - possibly a toString method, or something more specific.
RouterMessageHeader.toXMLString();
or XMLSerializer.stringify(routerMessageHeader); RouterMessageHeader.toXMLString();
Ended up as router_message_header_to_xml_string();
So 35 characters in all. Not quite terrible but also not very elegant. At least it says what it does :)I still can't help the feeling that the data structure leaked into the naming of the function and I see no way to solve that, I can't even imagine how one would go about that and still have a function with global scope (in itself something that you'd try to avoid wherever you could, but in this case we can't for various good reasons).
I've looked at making this a generic system but that increases the overall complexity of the bookkeeping (creation, destruction, modification) around the objects to such an extent that it probably isn't worth it (though I can see some other advantages of this approach, such as easier debugging).
send_router_message_header_as_xml_string(...)?
If it also does error handling of some sort, are we going to embed that in the name?My point is still ultimately the same as others here, but I'm trying to demonstrate it from the other direction. It isn't that the long function name is OK, it is that it is poorly decomposed into tasks. But digging another "why" back, the root cause for that is what you say later, that it "increases the overall complexity of the bookkeeping" etc., and the reason for that is that C isn't really that good a language for abstraction. After 40 years of experience with it we've managed to create some best practices that carry it far further than anyone could have imagined at the beginning, but when it gets down to it, when you have a language that doesn't abstract very well, you do eventually end up paying the price in functions like that. It probably is the right answer in C, no sarcasm, but that's not the same thing as saying it's the right answer in a more general sense.
(And to be more concrete, C has poor facilities for composing abstractions together without complication and loss. On a feature-by-feature basis you can make it do pretty much anything you want, Turing Complete etc etc, which makes it hard to see in blog-post-sized examples, but they don't wire together very well.)
RouterMessageHeader foo = new RouterMessageHeader();
foo.toXMLString();
There are other ways for foo to be derived, of course, and in many of them you never need to reference the ReferenceMessageHeader class name. msghead_to_xml()
Are there any 53-character function names in the multi-million line Linux kernel?The linux kernel is actually only about 100 K lines. And its naming conventions are not what I'd call an example of elegance either, to put it very mildly (many of the names are quite cryptic and require extensive study of the code around it to understand what a function does). If low symbol length would be an indicator of code quality then we'd all be using fXXXX where X is a digit of your choice.
The longest symbol in the kernel proper that I can quickly locate is 36 characters:
timer_stats_hrtimer_clear_start_info
It uses roughly the same convention that we use in our projects (a quite common one in large C projects): a module prefix
(if possible the same as the filename) an action and a bit that specifies further details.Even with that simple convention it can add up quickly.
And if you start linking against 3rd party libraries you're going to be looking at name clashes sooner or later, even if you're careful. Whoever at mysql decided to expose 'list_free', 'list_add', 'list_delete' and so on with global scope wasn't having their most lucid day. I wished I was kidding.
This is what I get from sloccount, which doesn't count blank lines or comments, for Ubuntu's old 3.0.0 kernel:
Totals grouped by language (dominant language first):
ansic: 9495321 (96.81%)
asm: 241006 (2.46%)
xml: 41486 (0.42%)
perl: 13987 (0.14%)
sh: 4117 (0.04%)
cpp: 3486 (0.04%)
yacc: 2987 (0.03%)
python: 2770 (0.03%)
lex: 1719 (0.02%)
awk: 708 (0.01%)
pascal: 231 (0.00%)
lisp: 218 (0.00%)
sed: 30 (0.00%)
Broken down by path (top 8): SLOC Directory SLOC-by-Language (Sorted)
5474678 drivers ansic=5469921,yacc=1688,asm=1475,perl=792,lex=779,
sh=23
1848085 arch ansic=1609109,asm=237452,sh=690,awk=470,pascal=231,
perl=58,python=45,sed=30
693955 fs ansic=693955
518275 sound ansic=518092,asm=183
481158 net ansic=481062,awk=96
290060 include ansic=288348,cpp=1670,asm=42
118198 kernel ansic=117893,perl=305
53773 mm ansic=53773
Overall I think your naming convention sounds reasonable; C is also my primary language. Your example was just too easy to shorten to resist ;-).That bit is the kernel. File systems, drivers and so on are best though of as plug-ins to the kernel. Architecture dependent code would probably normally expose only one set of symbols rather than all of the code, probably should have included memory management.
Likely if you include all that code you'll turn up a few more longish names, but the net effect is pretty much the same: really long names are rare when you've laid things out properly but 30 characters and up are certainly no exception.
edit: found a reference: http://www.drdobbs.com/cpp/extending-c-with-prolog/184409294
or
public string Serialize(MessageHeader header)
or if you really want to get fancy Serialize<T>(GenericHeaderObject someObject) which would then be called as Serialize<MessageHeader>(header)
It also implements a specific interface Painter<JComponent> which explains the Why and the javadoc is copied from its parent class.
So it is not as much an example of beauraucracy as of code-generation.
Alternative would have been hundreds of "AnonN" identifiers with N going well into the hundreds...
:)
The embedded error is, of course, in itself off-by-one, but the actual cause could be cache invalidation -- the list was extended from two things to three without updating the length counter.
(Excuse me if I've mentioned this before.) So, I met the guy who did the first implementation of Merge Sort which he wrote in assembly language on paper tape. One of his comments on C++ after noting how cluttered it could look: "So, is this today's equivalent of COBOL?"
> when you get out of the trivial program length domain into projects that are 100's of thousands of lines that this problem will sooner or later rear its ugly head
Global namespaces are evil. We have non-global namespaces, but programmers keep on acting like there's only one global namespace. In reality, in large projects, everything should be considered relative to intersecting areas of concern, and code should always explicitly reference the libraries being used locally. Python could be used this way, but I suspect most programmers act as if imports are just a way of getting what they want into their most convenient namespace, which effectively becomes the global one.
Talking about design patterns, the folks that develop the Spring framework apparently tried to put as many of them together as they could: there is a class named AbstractSingletonProxyFactoryBean (http://static.springsource.org/spring/docs/2.5.x/api/org/spr...) in the aop package. And, the class description is no less than "Convenient proxy factory bean superclass for proxy factory beans that create only singletons".
Take that, GoF.
Basically it's been deprecated, but its used for AOP interceptors. It gets a lot of flack, but there was a reasonable reason for the Spring developers to have created this class.
Oh, and the original documentation is pretty comical. But the latest documentation makes it very clear what it does:
http://static.springsource.org/spring/docs/current/javadoc-a...
I don't understand what I'm supposed to take away from this. That there exists in the world badly named Java classes? And? Is the implication here that because you found an example of a clumsily named Java class the entire language is an usuable write-off? Or that it's somehow indicative of all Java applications?
I know Java isn't cool, but I don't see what is achieved by staring, pointing and giggling because you found an example of its use that is ungainly.
http://msdn.microsoft.com/en-us/library/aa432714(office.12)....
If you look at it once more I guess that it is used as a Painter for MaximizeButton located in InternalFrameTitlePane of InternalFrameTitlePane of InternalFrame.
How would you name such thing?
[1] http://javadoc.bugaco.com/com/sun/java/swing/plaf/nimbus/pac...
I'm guessing this shouldn't even be exposed to anything outside of an InternalFrame anyway.
The rest of the world might simply say blah.bah.frame.paint and be done with it.
[1]http://weblogs.asp.net/rchartier/archive/2004/02/05/68350.as...
Interesting. It's long, but it's also pretty clear on what it does, and doesn't have any repeated words.
Reading this, I would guess that it's a notification of when the user starts editing a column, and indeed that's what it does. "Informs the System.Windows.Forms.DataGrid that the user has begun editing the column." is the official description in the API.
Anyways, we are shaming Java here because of one obviously automatically generated internal class.
http://code.google.com/codesearch#search/&q=%5Cw%7B60,%7...
E.g. TraversableResolverSpecifiedInValidationXmlNoDefaultConstructorGwtTest , DeleteContentTypeXmlDocumentResponseDeleteContentTypeXmlDocumentResult , and so on.
These super long names not part of any client interface, no one is ever going to have to type that monstrosity except for the guy writing the test. But when you see the failing test output that prints the test name, you already know what is failing.
You can have a small class name and a (comparatively) long comment, or just a long class name. Considering there is now no need for a comment and the test name is actually useful for debugging failed tests easily (you don't need to "dereference" the short test failure name to get the surrounding comment), this style is actually a win.
One can argue that this is the result of ignorance, that "good" Java programmers will avoid this trap. And yet, for all it's restrictions, it doesn't give much refactoring guidance. The proliferation of patterns (both for creation and relation) in Java is a weakness, not a strength, and the result is monstrosities like this. Training, experience and convention avoids these traps, but why do we create new languages if not to reduce the amount of training, experience and convention that a programmer needs to learn in order to be productive with an environment?
How many programmers have been affected by this internal class? How many programmers have used it and complain about it?
Java allows long identifier names and gives people the freedom to name however they like. Why is that a bad thing? You want syntax rules in the language to force short identifier names? We had those long while back and it's a really bad idea.
And BTW what is so wrong about imperative? It's simple to learn and simple to follow. It has solved many problems, given whatever the real world constraints. Just because functional is the in-thing now doesn't mean imperative is totally bad.
Nothing! The problems occur when people think that it's not.
And I really disagree with your hipster comment. You can indeed accomplish any task with Java, but that is damning with faint praise. The question is whether or not the environment gives the programmer adequate refactoring pressure to guide his decisions. Java provides almost no such pressure, resulting in a mess.
Many problems have been solved in Java despite of this, not because of it.
I don't really understand what you are trying to get at. Is it wrong or it isn't?
The hipster comment is spotted on. This post is evident of that attitude. The OP has to dig up an internal class whose name is probably generated to bash Java. And your original comment basically went further and claimed this long class name is the evident of what is so wrong with Java in general.
If there's no pressing pressure to refactor, then it has work well for its purpose. You want to limit class name to 8 characters to force programmers to pick shorter name? It's an internal class, for god sake. What's the impact on 99.99% of the programmer out there?
Development is a process of compromise and trade-off. Developers don't have infinite time and infinite budget to code. They have to pick their battle and do the more important things.
2. The phrase you're looking for is "spot on".
3. Generated code is a code smell. Again, you see a confusion between static and dynamic behavior.
2. Thank you for correcting my grammar. BTW the period goes inside the quotation marks as in "spot on."
3. While not often used, generated source code are useful as design calls for it. Not everything revolves around static and dynamic.
AVPlayer *player = <#A configured AVPlayer object#>;
CALayer *superlayer = <#Get a CALayer#>;
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[superlayer addSublayer:playerLayer];
https://developer.apple.com/library/ios/#documentation/AVFou...Why then people keep creating long class names in the first place? I get it that this particular example might be a generated name, but still, why not just create package hierarchy that represents the code properly?
Also wouldn't using package hierarchies automatically lead to a bit better design (more modular, more understandable)?
There are java applications that have been around for decades. I've worked in codebases that are over twenty years old. Some of these systems are responsible for billions of dollars and have been heavily tested (the others are responsible for billions of dollars and have been barely tested).
Say you are a consultant, and you're working on a shipping application that has been around since the late 90's and is responsible for moving goods where the sum total of all items in transport over a year is larger than the GDP of Taiwan.
In that application there is a Warehouse interface. Simple thing, basically it has a receive() and distribute() method that moves product from one location to another (warehouse.receive(truck) or warehouse.distribute(200,truck)).
Around 2000 someone needed to create an edge case because specific warehouses are only available during specific times of the year. Like black Friday to Christmas. Usually it is too much overhead to keep all these warehouses running so they are only open 1/2 the year (this doesn't happen, but work with me). So someone created class TimedWarehouse that will do this calculation (on date X no longer receive).
Now it is 2012 and you are just a contractor. The big problem with the TimedWarehouse is at the end of the year you MUST VACATE ALL GOODS (because the warehouse is going to shut down). For the last couple of years product has been lingering in these warehouses keeping them open longer (costing more money).
The best way to handle this is perhaps a batch process job that sends emergency shipments as it gets closer to the end of the year. So something that cleans the timed warehouses out. Now you're just a consultant, you can't rework the entire framework but you must keep with convention... what to do
TimedWarehouseProcessor (nice... but doesn't indicate that it is only used towards the end of the year)
TimedWarehouseYearlyCleanout (makes more sense, but is terribly specific, what about warehouses that are open twice a year)
TimedWarehouseCleanoutManagementUtility (Bingo! More generic sounding, and it is a 'utility')
Imagine the poor sap who might need to extend that class. The process repeats over time. More contractors following the rules of convention, larger and larger class names.
AbstractTimedWarehouseCleanoutManagementUtility TimedWarehouseCleanoutManagementUtilityFactory TimedWarehouseCleanoutManagementUtilityConfiguration TimedWarehouseCleanoutManagementUtilityDto etc...
Maybe using underscores in class names would be nice, but then it gets ambiguous how to punctuate something, which gets annoying.
Some object-oriented programmers do something similar, where their programs are expressed in a domain-specific language written as an object relationship graph. Only they skip the part where that language is supposed to make it easier to solve the problem.
What do I mean? Here's my (somewhat ancient) attempt at parody: http://pastebin.com/TyNrvRmB
It has all the hallmarks of production code I've seen in this style: it's about 20 times more than the necessary amount of code, it's subtly buggy, and it needs explanation because what it does is completely non-obvious.
It is arguably slightly easier to extend than the obvious solution, but at a great cost, and in a silly one-off program at that.
The worst part? This doesn't scream parody in some circles. This is just how things are done, as if anything less involved is fundamentally broken.
This is precisely how good Smalltalkers operated. It was very doable, because even constructs like conditional logic and "looping" (really iterators) were just ordinary calls. For example, if you wanted to implement "fuzzy logic" in Smalltalk it would just take a mere minutes to implement some methods like:
ifTrue:ifFalse:ifMaybe:
Then define a Maybe class and use it as the Maybe value and park some methods like that on it. Then this would let you write code like: result
ifTrue: [ "condition 1" ]
ifFalse: [ "something else" ]
ifMaybe: [
"handle maybe"
].JDK has a superb auto document building tool to extract all the classes in JavaDoc and letting people to find internal classes easier.
var foo = function(foo, bar){
var bar = function ( function (x) {
this.something = function (z) {
return function (y){}}}}};
//or something like that. Only a fool would
think the code above is real or even correct.Now if you said "Module" or "Builder", then you might be right.
com. sun.
java. swing.
plaf
nimbus, Internal
Frame? Internal Frame!
Title. Pane...
Internal Frame.
Title Pane
Maximize
Button Painter.But seriously, this just highlights one of the downsides of following "coding standards" religiously.