You are not logged in.
Pages: 1
rootEntry = new ZipEntry("")
{
public boolean isDirectory()
{
return true;
}
};
Ummm, what the hell is this? It's ruby-esque - someone please explain... I don't even know what to search for to find this explaination... is this a closure?
Offline
Anonymous Inner Class.
Dusty
Offline
So, um... they're overriding the java.utils.zip.ZipEntry class with "MyClass.ZipEntry" ? Kinda funky, but I guess it works...
Offline
That's pretty much what they're doing. I'm not sure its the smartest practice in this case. Anonymous inner classes are really useful for specifynig event listeners though. Its also useful if you need to provide a one-off implementation of a specific Java interface, for example.
Of course, we all prefer lambda.....
Dusty
Offline
that is some ugly, fugly, java code.
someone needs to get shot in the foot and beat over the head with a stick. for shame.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
not really, Cactus. That's kind of typical Java code. Its a hackish solution, but I don't think you could get the functionality offered in fewer lines of code.
In Java, that is. ;-)
Dusty
Offline
fewer lines of code is not always better. I would aim for a bit more readability and maintainability. I mean..
it is likely that somewhere down the line, someone else will have to look at that code..and deal with it.
I think breaking it out into a class definition before using it (remove the inline syntax) would be far more readable, and would appear less "hackish".
Just because it works, and is concise, doesn't make it good. Think perl obfuscation awards...
/me shudders
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Well, that looks pretty readable to me, to be honest. On the other hand, Java isn't cool....
Dusty
Offline
one man's readable, is another man's refuse I guess.
hooray for middle of the road!
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Ruby is never that Ugly
Mr Green
Offline
lol... you haven't seen much of my code then.
*evil grin*
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
emmm I have & it was sweeet 8)
Mr Green
Offline
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
The language that I prefer to program in is java, I can read anonymous inner classes, but I do find them annyoing. I prefer proper class definitions, although you have to get creative with the class names after a while.
v/r
Suds
Offline
The language that I prefer to program in is java, I can read anonymous inner classes, but I do find them annyoing. I prefer proper class definitions, although you have to get creative with the class names after a while.
In this code, though, it was a hack - basically there's no way to fool a ZipEntry class.. it needs real data. This little hack created a fake ZipEntry as a root node of a zip file - kinda cool.
PS It was an example FUSE filesystem for JFuse (or Fuse-J, whatever)
Offline
fewer lines of code is not always better. I would aim for a bit more readability and maintainability. I mean..
it is likely that somewhere down the line, someone else will have to look at that code..and deal with it.
However, there are indeed times where smaller class size is a boon.
I'm programming apps for cell phones right now, in J2ME. I've used anon. inner classes to get one-off implementations of other classes with minimal increase in code size, and code size is pretty important, if you want to support low-end phones.
Offline
I dunno. I tend to think that such jobs are the realm of the compiler. In theory, a compiler shouldn't use *too* much more space to store a discreen simple class, or a simple inner class. Granted, scope will make it use more memory to some degree..and it might not get garbage collected/freed up at the same time, or at all...but again. I tend to think that is something that the compiler should really worry about.
We are talking about simple semantics here though...my "make the compiler think" philosophy is for simple differences only. I don't believe this can be expanded to complex cases.. but then again. you wouldn't use anonymous inner classes for complex things anyway, right?
As for taking up more space, again.. the bytecode difference *should* be somewhat negligable. I am not sure if this is the case though. If not, then by all means... your case is definately valid, and I would agree with you.
In cases such as the one you presented, if the size was considerably different, then it would indeed make a difference.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Hm... I suppose using a named inner class, extending the class I want and overriding the necessary public methods, probably shouldn't enlarge the codebase all that much...
However, the extended functionality is only ever used in that one section, so it's clearer, to me, when I read the code exactly what it's being used for when I write it that way. If the functionality were to be needed in other places, of course I'd extend the existing class - I don't know why, but this way 'feels' cleaner to me, call me crazy.
Offline
Pages: 1