Re: Duck typing alows true polymorfisim
In comp.lang.java.advocacy, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote on 25 Aug 2006 12:05:21 -0700 <[EMAIL PROTECTED]>: > lets say you want a generic numerical algorithom like sum > > Ruby > > def sum lst > lst.inject(0){|total,current| total*current} > end > > Java // i dont know if there is a numeric super class for numbers > > class Sum{ > public static int sum(int[] lst){ > int total = 0; > for(int current : lst){ > total+=current; > } > return total; > } > // repeat for all other number types > } > There isn't; Java makes the distinction between an int and an Integer, a double and a Double. Java 5 did introduce autoboxing, which makes things like Number[] numbers = new Number[]{1, 2.3, 4, 5.6}; possible, and Number is a baseclass for both Integer and Double (but not int and double). Therefore, one could write: public class Sum { public static double sum(int[] lst) { Number[] nlst = new Number[lst.length]; for(int i = 0; i < nlst.length; i++) nlst[i] = new Integer(lst[i]); return sum(Arrays.asList(nlst)); } public static double sum(double[] lst) { Number[] nlst = new Number[lst.length]; for(int i = 0; i < nlst.length; i++) nlst[i] = new Double(lst[i]); return sum(Arrays.asList(nlst)); } public static double sum(float[] lst) { Number[] nlst = new Number[lst.length]; for(int i = 0; i < nlst.length; i++) nlst[i] = new Double(lst[i]); return sum(Arrays.asList(nlst)); } public static double sum(Number[] lst) { return sum(Arrays.asList(lst)); } public static double sum(Collection lst) { double sum = 0; for(Iterator i = lst.iterator(); i.hasNext()) sum += i.next().doubleValue(); return sum; } } A rather ugly but possibly useful duckling. -- #191, [EMAIL PROTECTED] Windows Vista. Because it's time to refresh your hardware. Trust us. -- http://mail.python.org/mailman/listinfo/python-list
Re: Duck typing alows true polymorfisim
In comp.lang.java.advocacy, Jeroen Wenting wrote on Wed, 30 Aug 2006 20:18:52 +0200 <[EMAIL PROTECTED]>: > > "Simon Forman" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> [EMAIL PROTECTED] wrote: >>> lets say you want a generic numerical algorithom like sum >>> > >> What's your question? (Or, if no question, point?) :-) >> > Reads like the weekly "Ruby is better than Java because X" post. > Well, FWIW one could throw this into the pot and watch it explode: http://www.approximity.com/ruby/Comparison_rb_st_m_java.html :-) This table needs some work. The leftmost column is unidentified, for example ("Capability" or "Feature" suggests itself here) and each of these capabilities or features should probably have a link to a short description of the capability or feature, preferably with an example. Also, one language is very conspicuous by its absence: C#. One could also add C, Basic, and ISO Pascal; the first is widely used but lacks polymorphism, inheritance, dynamic casting, etc., and the last is probably not used anywhere in its form (though dialects are plenty), since one can't do anything *with* it, really -- though IIRC someone has told me it can at least open an arbitrary file now, as opposed to having the user pass one down in the program identifier list. :-) As for the middle one: which dialect? Was it ever standardized? Visual Basic is a very object-oriented language in spots, but it's not the only variant; I used to use at least 4 other variants off and on: GWBasic -- old IBM PCs ABasic -- Amiga variant AmigaBasic -- Microsoft-sponsored Amiga variant HP Basic (?) -- load tape into very old HP 21xx-series computer and one had a multitasking Basic which could do the simpler stuff, but its error diagnostics were pure numeric: ERROR 67 IN LINE 20. Fortunately, we had plenty of pamphlets detailing the errors. Also, Java now has templates. (The implementation is pretty gross and has some quirks, IMO, but it's better than nothing.) C++ has a typing system ("type_of" or some such; I'd have to look) which yields little more than the mangled type name and static inheritance testing capabilities. Of course C++ doesn't have dynamic inheritance anyway. One could include additional capabilities: Dynamic type creation. I don't know if Java has this or not. One can of course attempt bytecode synthesis -- I think that's what BCEL uses -- but that's a bit of a hack. Dynamic method creation. Java does *not* have this. AIUI Smalltalk-80 does; one can take an existing class and add methods thereto. Dynamic method override. This may be an artificial distinction but in some languages -- Smalltalk-80 again, presumably -- one can take an existing method implementation and override it in the same class, but without allowing the creation of new methods. How this would be enforced without additional keywords and/or a full-fledged ACL method/metadata system, I for one do not know. Dynamic method deletion. I for one might only want this in the context of a "sandbox" but if one can create methods, one should be able to delete them as well if only because of undo. Dynamic method rename. This could lead to much madness but this might be useful during sandboxing. Dynamic method signature changing. Eclipse has a reasonable way of doing it using source but I'll admit to wondering whether it makes sense given a Method descriptor whether one should be able to edit (as opposed to viewing or invoking) that descriptor, and when. One might implement this as a new method, followed by a delete of the old one. Dynamic other method deletion. If one can delete one's own methods in an edit session, should it be possible to delete others' methods too? An interesting question. Dynamic inheritance. For those languages that support inheritance one might liken it to changing what the language inherits or implements on the fly. I don't know of any language apart from Smalltalk that can even think about allowing dynamic inheritance, but it's a thought. Operator overload (e.g., C++'s operator ==()). Name overload. C does not have it; C++ and Java do. I suspect Ruby and Python do as well. Globals. Java has no globals as such, unless one counts class names. C is all globals, unless one counts statics. Unnamed classes. new Runnable() { public void run() {...} } is Java's contribution. Can be useful. Nested classes. Primitive types -- in other words, the int<->Integer dichotomy we all know and love in Java; such also exists in C++ and IINM C#. I'm not sure if Smalltalk has such a concept, or not; Smalltalk allows overrides on numbers. (In Java one might contemplate 2.toString(), for example!) Arbitrary integer size. The only language I know having this is Common LISP. Explicit module-level identifier scoping. In C++ this might be implemented during link using the -E flag on ld, for example (there is the Microsoft concept of exporting in their DLLs, which is vaguely similar as well
Re: Duck typing alows true polymorfisim
In comp.lang.java.advocacy, Tor Iver Wilhelmsen <[EMAIL PROTECTED]> wrote on 31 Aug 2006 18:31:15 +0200 <[EMAIL PROTECTED]>: > The Ghost In The Machine <[EMAIL PROTECTED]> writes: > >> Also, one language is very conspicuous by its absence: C#. > > He does not date any of the updates, so it's unclear how recently it > has been updated (a lot of the web is stale, like a rotting tree in a > forest.) Aye; my webpage has a similar problem. :-) > >> AmigaBasic -- Microsoft-sponsored Amiga variant > > Well, at the time Microsoft were the makers of the de-facto BASIC > implementations - M-BASIC for CP/M, the various variants in VC-20 and > C-64 and later derivates of those, and many other home computers. > "Sponsored" should probably be "created" instead - I assume they were > paid for the job. OK, "created" then. :-) > >> Also, Java now has templates. (The implementation is pretty gross >> and has some quirks, IMO, but it's better than nothing.) C++ has a >> typing system ("type_of" or some such; I'd have to look) which >> yields little more than the mangled type name and static inheritance >> testing capabilities. Of course C++ doesn't have dynamic inheritance >> anyway. > > There's the virtual stuff, and you could conceivably implement dynamic > inheritance via the bare-bones C layer - like function pointers. The > type information in C++ (RTTI) is optional. Oh yeah, that's true. Still not all that dynamic, though, unless one recompiles. > >> Dynamic type creation. I don't know if Java has this or not. One can >> of course attempt bytecode synthesis -- I think that's what BCEL >> uses -- but that's a bit of a hack. > > Groovy could possibly be used for that; also IIRC Java 6 adds some > features for that. I seem to recall security implications being one > reason this ability wasn't included from the start. Not familiar with Groovy; I'll have to look into that. It's amazing what's out there; one of the problems with Free Open Source Software (FOSS) is that there's multiple choices for the obvious stuff. :-) > >> Dynamic method creation. Java does *not* have this. AIUI >> Smalltalk-80 does; one can take an existing class and add methods >> thereto. > > Yes, but that's because a Smalltalk program lives inside a big binary > "image" that is mutable. Woe unto you if that big binary file gets > corrupted. Indeed. I for one would want Smalltalk to have the ability to transcript certain messages but would have to look. (One might call that an edit audit trail.) > >> Dynamic method deletion. I for one might only want this in the >> context of a "sandbox" but if one can create methods, one should be >> able to delete them as well if only because of undo. > > The problem with deleting a method is whether the runtime can handle > it: Smalltalk has doesNotUnderstand:#aMessage, Java has > NoSuchMetohdError - what does C++ do? A zeroed virtual method would > cause a pure virtual method call error, which I guess C++ programmers > are trained to take into account. I'd frankly have to look. My thinking is that it's a message followed by an exit(). > Also, if class A has a method and > you delet it in subclass B, it breaks the Liskov Substitution > Principle, there B should be able to function where an A is wanted. Heh...an interesting name; I'm not familiar with that issue. Of course it's important for B to be an A in many cases, though AFAICT usually what happens is that A declares a method virtual with an implementation and B munges it. > >> Dynamic method rename. This could lead to much madness but this >> might be useful during sandboxing. > > A method's name and its "address" are distinct, but for dynamic method > dispatch, what about any other code that doesn't know the new name but > assumes the method is called the same? What indeed? Much madness. > >> Dynamic inheritance. For those languages that support inheritance >> one might liken it to changing what the language inherits or >> implements on the fly. I don't know of any language apart from >> Smalltalk that can even think about allowing dynamic inheritance, >> but it's a thought. > > If you can change a Perl class, er, module's @INC array I think that > would support it. > >> Operator overload (e.g., C++'s operator ==()). > > Or rather "dotless/prefix method invocation with the added baggage of > precedence rules". Smalltalk solves this by 1) not having those > precedence rules, 2) have dotless method invocation a
Re: I want to ask you the most important question of your life. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? The reason some people don't know for sure if they are going to Heaven when they die is because they just don't know. The good news is that you can know for sure you are going to Heaven. May 24, 2005 10:49:20 am
In comp.os.linux.advocacy, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote on 24 May 2005 07:48:47 -0700 <[EMAIL PROTECTED]>: > > THE MOST IMPORTANT QUESTION OF YOUR LIFE > > This is the most important question of your life. > > The question is: Are you saved? I'm tempted to ask if you're *shaved* (I'm not). Why you're asking this in technical groups is far from clear. God doesn't care if you're using Python, C, Matlab, Linux, or OSX, at least, not as far as I know. It is vaguely possible that the Almighty has in fact upgraded his internal communications network to include TCP/IP, MBone, and Etherial Prayer Protocol (EPP), but I'd prefer to see hard evidence. Followups to a slightly more logical place. :-) [rest snipped] -- #191, [EMAIL PROTECTED] It's still legal to go .sigless. -- http://mail.python.org/mailman/listinfo/python-list
Re: * * * Please Read And/Or Print This! * * * Press [Ctrl][P] Keys On Your Keyboard To Print >> June 1, 2004 8:23:43 pm >> http://115639.aceboard.net/forum2.php?rub=158&cat=61&login=115639&page=0#id96 << * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
In comp.os.linux.advocacy, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote on 1 Jun 2005 17:23:05 -0700 <[EMAIL PROTECTED]>: > * * * Please ... ... go jump in a lake. [rest snipped] -- #191, [EMAIL PROTECTED] It's still legal to go .sigless. -- http://mail.python.org/mailman/listinfo/python-list