You are not logged in.

#1 2005-12-02 16:29:00

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

wtf java syntax?

      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

#2 2005-12-02 16:34:25

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Offline

#3 2005-12-02 16:45:08

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: wtf java syntax?

So, um... they're overriding the java.utils.zip.ZipEntry class with "MyClass.ZipEntry" ? Kinda funky, but I guess it works...

Offline

#4 2005-12-02 16:54:54

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: wtf java syntax?

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

#5 2005-12-02 17:15:04

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: wtf java syntax?

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

#6 2005-12-02 17:19:44

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: wtf java syntax?

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

#7 2005-12-02 17:23:19

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: wtf java syntax?

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

#8 2005-12-02 17:28:50

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: wtf java syntax?

Well, that looks pretty readable to me, to be honest. On the other hand, Java isn't cool....

Dusty

Offline

#9 2005-12-02 19:15:38

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: wtf java syntax?

one man's readable, is another man's refuse I guess.
hooray for middle of the road! wink


"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

#10 2005-12-02 19:23:26

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,745

Re: wtf java syntax?

Ruby is never that Ugly  roll


Mr Green

Offline

#11 2005-12-02 19:24:27

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: wtf java syntax?

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

#12 2005-12-02 19:56:36

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,745

Re: wtf java syntax?

emmm I have & it was sweeet  8)


Mr Green

Offline

#13 2005-12-02 20:05:24

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: wtf java syntax?

smile


"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

#14 2005-12-02 20:44:41

sudman1
Member
From: Huntingdon, UK
Registered: 2005-02-18
Posts: 143

Re: wtf java syntax?

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

#15 2005-12-02 22:51:34

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: wtf java syntax?

sudman1 wrote:

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

#16 2005-12-02 23:25:51

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: wtf java syntax?

cactus wrote:

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

#17 2005-12-02 23:37:49

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: wtf java syntax?

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

#18 2005-12-03 02:28:18

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: wtf java syntax?

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

Board footer

Powered by FluxBB