Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 61 62 [63] 64 65 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95785 times)

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #930 on: February 18, 2011, 02:32:10 pm »

I retract my previous comment; I forgot that it was basically necessary for doing GUI programming in Java.


New rule: don't do GUI programming in Java. :p

You don't have to use anonymous or internal classes even with GUI's, but that is the primary place that it makes things easier.

I generally avoid doing gui's in java as well (professionally 95% has been server side java and the rest was applets, privately nearly everything I write in java has been command line tools). But I will be soon, need a gui for world building soon.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #931 on: February 18, 2011, 02:48:02 pm »

What's good for doing gui's then?
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #932 on: February 18, 2011, 02:54:31 pm »

What's good for doing gui's then?

while using java? you don't have a lot of alternatives. It is either command line, AWT/Swing or a web front end.

Edit: I forgot that you can build your own gui by drawing it on the screen with bitmaps and OpenGl if you are particularly masochistic.
« Last Edit: February 18, 2011, 03:54:03 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #933 on: February 18, 2011, 03:44:29 pm »

I retract my previous comment; I forgot that it was basically necessary for doing GUI programming in Java.


New rule: don't do GUI programming in Java. :p
Thank god programmers usually have full control over the language they'll be writing things in, no? :P


Anyway, that's not the only reason to use anonymous classes in Java, but they almost always serve as a thin wrapper for a piece of code that's obtained in one place but needed in another (You could for example use it to implement a limited form of lambda calculus) and using it for any other purpose is probably a good way to get even non-psychopathic programmers chasing you with an ax. When used with care they're not going to be worse then function pointers in C or delegates in C# though. As I said, if you end up in a situation where using an anonymous class would improve things you'll know it. Till then, don't even think about it ;)
« Last Edit: February 18, 2011, 03:47:46 pm by Virex »
Logged

Blank Expression

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #934 on: February 18, 2011, 06:29:17 pm »

Anyway, that's not the only reason to use anonymous classes in Java, but they almost always serve as a thin wrapper for a piece of code that's obtained in one place but needed in another (You could for example use it to implement a limited form of lambda calculus) and using it for any other purpose is probably a good way to get even non-psychopathic programmers chasing you with an ax. When used with care they're not going to be worse then function pointers in C or delegates in C# though. As I said, if you end up in a situation where using an anonymous class would improve things you'll know it. Till then, don't even think about it ;)
Anonymous classes are demonstrably worse than C# delegates - in addition to superfluous barf in your code files, they increase permgen size by quite a bit per-class for the same end benefit as a delegate.

They're a terrible hack to address a Java deficiency, and they can't really be defended.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #935 on: February 19, 2011, 08:22:07 am »

fwrite wants me to save it's return value. Is doing this safe?
Code: [Select]
void* junk;
junk = (void*)fwrite(...);
(note: This is a little script that writes stuff to a file, I don't care about fwrite's return value.)
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #936 on: February 19, 2011, 09:15:17 am »

Anonymous classes are demonstrably worse than C# delegates - in addition to superfluous barf in your code files, they increase permgen size by quite a bit per-class for the same end benefit as a delegate.

They're a terrible hack to address a Java deficiency, and they can't really be defended.

Why did they go with that model anyway? I'm sure there was a pre-compile java hack that had really nice lamba style support (although googling I fail to find any evidence of it so maybe I just imagined it) whereas the model they used seems clunky by comparison.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #937 on: February 19, 2011, 09:35:41 am »

If you aren't going to use it, and ignoring it doesn't cause a memory leak, then don't bother even with a temporary variable, just ignore the return value. However, often the return vvalue gives valuable information, like if the function call failed in some way, so it's not always wise to just ignore it.
Logged
Eh?
Eh!

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #938 on: February 19, 2011, 09:40:37 am »

In the case of fwrite it is generally the number of bytes written so you can test if your whole datablock was written or if you had an error.

If you don't care then ignore it as qwerty said, you shouldn't be required to save the return value.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #939 on: February 19, 2011, 10:05:42 am »

gcc screams when I don't, so I'll leave it that way, I guess.
Code: [Select]
sound.c:63:27: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
« Last Edit: February 19, 2011, 10:14:29 am by ILikePie »
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #940 on: February 19, 2011, 10:14:55 am »

That's a warning, not an error, so it's not fatal. Gcc is just telling you you're doing something you probably don't want to do, but it'll be able to compile it if you turn of the warning.

Anonymous classes are demonstrably worse than C# delegates - in addition to superfluous barf in your code files, they increase permgen size by quite a bit per-class for the same end benefit as a delegate.

They're a terrible hack to address a Java deficiency, and they can't really be defended.

Why did they go with that model anyway? I'm sure there was a pre-compile java hack that had really nice lamba style support (although googling I fail to find any evidence of it so maybe I just imagined it) whereas the model they used seems clunky by comparison.
Clojure and Scala are 2 functional programing languages built on the JRE that can communicate directly with Java, so it's indeed possible to implement anonymous functions in Java. It's just that the language designers of Java (the language) chose no to support it. Perhaps they can't find a good way to implement it within Java's ideology of treating everything as an object? (probably not though, because C# uses the same ideology and provides delegates to handle things like this elegantly)
« Last Edit: February 19, 2011, 10:26:19 am by Virex »
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #941 on: February 19, 2011, 10:52:25 am »

http://openjdk.java.net/projects/jdk7/features/

Java 7 will have the addition of lambda expressions (I think that implies that there will be anonymous functions, am I correct?) to the core language. There seems to be a lot of Java GUI bashing, but I haven't really had any experience in GUI programming outside of Java. I'm curious as to what qualifies as good GUI programming.
« Last Edit: February 19, 2011, 10:54:45 am by Normandy »
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #942 on: February 19, 2011, 11:09:29 am »

http://openjdk.java.net/projects/jdk7/features/

Java 7 will have the addition of lambda expressions (I think that implies that there will be anonymous functions, am I correct?) to the core language.
To some extend, yes. Not being able to capture mutable variables is going to make writing closures difficult, but for many other tasks it's pretty close to normal anonymous functions.
Logged

Blank Expression

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #943 on: February 19, 2011, 11:26:27 pm »

Anonymous classes are demonstrably worse than C# delegates - in addition to superfluous barf in your code files, they increase permgen size by quite a bit per-class for the same end benefit as a delegate.

They're a terrible hack to address a Java deficiency, and they can't really be defended.

Why did they go with that model anyway? I'm sure there was a pre-compile java hack that had really nice lamba style support (although googling I fail to find any evidence of it so maybe I just imagined it) whereas the model they used seems clunky by comparison.
It begins with "they're not all that bright."

C# is not the first time a Java-alike has had delegates. J++ had them too. Way back in the mists of 1995, Microsoft wanted to adopt Java for Windows programming. They came to the conclusion, however, that many parts of Java were somewhere around "canned ass". And it was true--many parts of Java are absolutely broken and have been since the earliest days of its existence. Remote Method Invocation is fundamentally stupid; Java Native Interface is just a terrible spec, hard to implement, and slower than balls. So Microsoft departed from a strict interpretation of the Java spec, providing optional components that, while restricting your application to the MSJVM (and later Kaffe, not that the "hurr, Microsoft is evil" crowd wants to rememver that), allowed you to write much nicer, much more effective Windows applications, using Java. These included Windows Foundation Classes, a Java analogue to the C++ MFC libraries, and some language extensions, including a callback/delegate system.

The Sun response to Microsoft adding delegates to J++, itself tellingly stupid, can be found here:

http://java.sun.com/docs/white/delegates.html

Sun was never a good shepherd for Java, and the overly academic point of view expressed in that article are a big part of why. They are undoubtedly correct in the notion that inner classes are "more object-oriented" than delegates. And y'know what? Who cares? Something that is easy and effective for developers to use is worth more to those developers than a perfect object model. (The argument they make is weakened by the obviously effective, solidly OOP implementation of delegates in C#, fitting seamlessly into the ecosystem without a problem.)
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #944 on: February 20, 2011, 08:24:17 am »

They are undoubtedly correct in the notion that inner classes are "more object-oriented in line with their concept of object orientation" than delegates.
There is not really one, unifying "object orientation system". Java just implements one of the more popular paradigms, but for example Javascript handles inheritance via prototyping and some some languages (amongst which C# since version 4.0, see a pattern here?) use multimethods instead of or as a supplement to message passing.
Logged
Pages: 1 ... 61 62 [63] 64 65 ... 78