Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11293

Re: Java is killing me! (AKA: Java for Pythonheads?)

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'definitions': 0.07; 'through,': 0.07; 'worse': 0.07; 'python': 0.08; 'argument,': 0.09; 'arguments,': 0.09; 'definitions.': 0.09; 'from:addr:python': 0.09; 'integer,': 0.09; 'myself,': 0.09; 'sake': 0.09; 'wrappers': 0.09; 'programmer': 0.10; 'float': 0.13; 'def': 0.15; 'forum.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'ported': 0.16; 'quant': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'subject:?)': 0.16; 'subject:Java': 0.16; 'xs:': 0.16; 'wrote:': 0.16; 'arguments': 0.18; 'int': 0.18; 'java,': 0.19; 'java': 0.21; 'header:In-Reply-To:1': 0.22; 'work,': 0.23; 'default,': 0.23; 'optional': 0.23; 'code': 0.25; 'tests': 0.25; 'code.': 0.26; "i'm": 0.27; 'function': 0.27; '(the': 0.28; 'classes': 0.28; 'raise': 0.28; 'received:84': 0.28; 'second': 0.29; 'asking': 0.29; 'least': 0.31; 'does': 0.32; 'implement': 0.32; "what's": 0.33; 'to:addr:python-list': 0.33; "i've": 0.34; '...': 0.34; 'header:User-Agent:1': 0.34; '(as': 0.34; 'test': 0.34; 'reply-to:addr:python.org': 0.34; 'uses': 0.35; 'question': 0.36; 'problems': 0.36; 'another': 0.37; 'sequence': 0.37; 'with.': 0.37; 'but': 0.37; 'forgive': 0.38; 'some': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'finding': 0.39; 'option': 0.39; 'either': 0.39; 'to:addr:python.org': 0.39; 'third': 0.40; "it's": 0.40; 'more': 0.60; 'immediate': 0.63; 'forum': 0.64; 'natural': 0.65; 'due': 0.66; 'nothing.': 0.67; 'mountain': 0.68; 'header:Reply-To:1': 0.71; 'readers': 0.71; 'reply-to:no real name:2**0': 0.71; 'elaborate': 0.84; 'float)': 0.84; 'cope': 0.91
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AlkbAORjRU5UXebj/2dsb2JhbABBmHCOfA13gUABAQU4Mw0RCwgQCRYPCQMCAQIBDTgTCAEBh227BYZHBItdSYt2i2Y
Date Fri, 12 Aug 2011 18:35:46 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Java is killing me! (AKA: Java for Pythonheads?)
References <j23mbe$nfe$1@reader1.panix.com>
In-Reply-To <j23mbe$nfe$1@reader1.panix.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2227.1313170612.1164.python-list@python.org> (permalink)
Lines 73
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313170612 news.xs4all.nl 23866 [2001:888:2000:d::a6]:41533
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11293

Show key headers only | View raw


On 12/08/2011 18:02, kj wrote:
>
>
>
> *Please* forgive me for asking a Java question in a Python forum.
> My only excuse for this no-no is that a Python forum is more likely
> than a Java one to have among its readers those who have had to
> deal with the same problems I'm wrestling with.
>
> Due to my job, I have to port some Python code to Java, and write
> tests for the ported code.  (Yes, I've considered finding myself
> another job, but this is not an option in the immediate future.)
>
> What's giving me the hardest time is that the original Python code
> uses a lot of functions with optional arguments (as is natural to
> do in Python).
>
> As far as I can tell (admittedly I'm no Java expert, and have not
> programmed in it since 2001), to implement a Java method with n
> optional arguments, one needs at least 2**n method definitions.
> Even if all but one of these definitions are simple wrappers that
> call the one that does all the work, it's still a lot of code to
> wade through, for nothing.
>
> That's bad enough, but even worse is writing the unit tests for
> the resulting mountain of fluffCode.  I find myself writing test
> classes whose constructors also require 2**n definitions, one for
> each form of the function to be tested...
>
> I ask myself, how does the journeyman Python programmer cope with
> such nonsense?
>
> For the sake of concreteness, consider the following run-of-the-mill
> Python function of 3 arguments (the first argument, xs, is expected
> to be either a float or a sequence of floats; the second and third
> arguments, an int and a float, are optional):
>
>     def quant(xs, nlevels=MAXN, xlim=MAXX):
>          if not hasattr(xs, '__iter__'):
>              return spam((xs,), n, xlim)[0]
>
>          if _bad_quant_args(xs, nlevels, xlim):
>              raise TypeError("invalid arguments")
>
>          retval = []
>          for x in xs:
>              # ...
>              # elaborate acrobatics that set y
>              # ...
>              retval.append(y)
>
>          return retval
>
> My Java implementation of it already requires at least 8 method
> definitions, with signatures:
>
[snip]

I would declare:

      short[] quant (float[], int    , float)
      short   quant (Float  , Integer, Float)

and see how it goes.

"float" and "int" should be boxed to "Float" and "Integer"
automatically.

If the second and third arguments are frequently the default, then I
would also declare:

      short[] quant (float[])
      short   quant (Float  )

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Java is killing me! (AKA: Java for Pythonheads?) kj <no.email@please.post> - 2011-08-12 17:02 +0000
  Re: Java is killing me! (AKA: Java for Pythonheads?) Nathan Rice <nathan.alexander.rice@gmail.com> - 2011-08-12 13:15 -0400
  Re: Java is killing me! (AKA: Java for Pythonheads?) MRAB <python@mrabarnett.plus.com> - 2011-08-12 18:35 +0100
    Re: Java is killing me! (AKA: Java for Pythonheads?) rav <rafalgulinski@gmail.com> - 2011-08-13 06:17 -0700
  Re: Java is killing me! (AKA: Java for Pythonheads?) Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-12 19:45 +0200
  Re: Java is killing me! (AKA: Java for Pythonheads?) Miki Tebeka <miki.tebeka@gmail.com> - 2011-08-12 11:18 -0700
  Re: Java is killing me! (AKA: Java for Pythonheads?) Chris Angelico <rosuav@gmail.com> - 2011-08-12 21:39 +0100
  Re: Java is killing me! (AKA: Java for Pythonheads?) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-08-12 23:31 -0700
  Re: Java is killing me! (AKA: Java for Pythonheads?) Dirk Olmes <dirk@xanthippe.ping.de> - 2011-08-15 16:16 +0000

csiph-web