[Chicago] Advice about a Java program?

Lewit, Douglas d-lewit at neiu.edu
Sat Oct 11 01:43:42 CEST 2014


Hey Mike,

Thanks for the feedback but I love double spacing my code!  It's easier to
read!

Actually, I almost always use Emacs as my text editor.  (I love Emacs. )
Emacs is pretty good about tabbing automatically, although if I want to I
have the option of overriding or changing the defaults.  One of the nice
things about Emacs is that when you type a closing brace, you get this
message at the bottom telling you which logic structure that brace is
closing.  How nice!  You definitely don't get that in nano/pico or
JGrasp.   : (

Yes, I know the main method is really long, but don't forget about those
overloaded methods at the bottom!  Do I get a couple extra points for
those?   : )

This isn't an assignment for my class.  This is just something I wanted to
try because.... well, it sounded interesting.

I will confess that at the time of writing the code it makes perfect sense
to me.  Then if I go back to it a little later on I'm like.... what the
hell is this???    : )

I like programming because of the intellectual challenge, but I kind of
hate it because I know my professors are grooming me to be some drone in
the business world.  That's the part of programming that I'm not especially
fond of.  Drones don't have to think creatively.  They just have to follow
orders!  Oh well.

On Fri, Oct 10, 2014 at 3:11 PM, Michael Maloney <tac at tac-tics.net> wrote:

> @Philip, I believe Douglas is taking a class, so unfortunately, Clojure is
> probably not an option. (Although I encourage anyone to look at Clojure).
>
> A few comments on the code:
>
> Watch your alignment. On line 11, for example, the block inside the main
> method lines up with the declaration. You want to tab it. Even though Java
> doesn't enforce indentation, you should pretend it is. On line 18 and other
> places, you've tabbed the curly brace. This is a relatively stylistic
> choice. (I think C programmers use it still, though?) Java's official style
> guide says opening curly braces should come at the end of the same line,
> closing curly braces should line up with the if/for/while statement or
> method declaration that opened it:
>
> while (...) {
>     // ...
>     // ...
>     // ...
> }
>
> At 101 lines of code, your main method is excruciatingly long. Most
> methods you write should to be between 1 and ~8 lines long. Highly
> algorithmic code (say, an implementation of a mergesort) might be around 30
> lines long. The main method of a script might be that long too in some
> cases. But 101 is enough to exhaust anyone's attention. As I mention in the
> other email I sent, you shouldn't need to double-space all of your code.
> And you should consider splitting the main method up into separate smaller
> "helper" methods.
>
> A good way to do this might be to break out these pieces: the code to read
> the user's dimension input (~18 lines), the user's choice of data type (~10
> lines), the user's entry input (~20 lines), and the output code (~30 lines).
>
> Even in cases where splitting a method up into separate pieces doesn't
> decrease the total line count of your program, it often helps your codes
> readability considerably. Especially if you choose your method names
> carefully, it's easier to glance at the function call and *guess* what it
> should be doing, without having to be presented with the gory details.
>
> I know none of this addresses your question directly, but often, having
> your code more organized will help you isolate the errors you run into.
> Rearranging your code to make it more understandable is what we call this
> refactoring. I don't know about the rest of the community, but I've always
> found it very relaxing. Like trimming a bonzai tree or raking the sand in a
> zen garden :)
>
>
> On Fri, Oct 10, 2014 at 1:21 PM, Philip Doctor <diomedestydeus at gmail.com>
> wrote:
>
>>
>> For console output I'd recommend checking the docs on how to pad numbers
>> into columns (
>> http://docs.oracle.com/javase/tutorial/java/data/numberformat.html).  If
>> this is not a homework assignment and you're allowed to use 3rd party
>> libraries I've never used it but I heard good things about
>> https://code.google.com/p/j-text-utils/ .
>>
>> Of course if you're not doing it for a class I'm not totally sure why you
>> would reinvent the wheel on matrix multiplication as there's tons good math
>> libraries out there for java that will do this:
>>
>> http://commons.apache.org/proper/commons-math/
>> http://math.nist.gov/javanumerics/jama/
>> https://code.google.com/p/efficient-java-matrix-library/
>>
>> (a dozen more if you google it)
>>
>> Best of luck (p.s. if jvm is a requirement but java isn't, I'm going to
>> fan-boy plug clojure as a language you might enjoy more given your
>> statements about python).
>>
>> /off-topic
>>
>>
>> On Fri, Oct 10, 2014 at 12:43 PM, Lewit, Douglas <d-lewit at neiu.edu>
>> wrote:
>>
>>> This is probably the wrong forum for this, but I thought I would give it
>>> a try because the people at my university cannot always be counted on for
>>> good feedback.
>>>
>>> I wrote this Java program that multiples two matrices.  I think it's
>>> basically pretty good.  (And doing this in Python is WAY EASIER because
>>> Python doesn't distinguish between lists of ints and lists of doubles, and
>>> actually allows both data types to get combined in the same list. )
>>>
>>> However, I'm having some issues with the formatted output of my "float"
>>> matrices.  They are technically doubles, but in the program I refer to them
>>> as floating point values for the sake of clarity because some users of the
>>> program may not know what a double is.  Is that like a double martini?  : )
>>>
>>>
>>> I'm trying to get all of my numbers lined up properly in their
>>> respective columns, but it's just not working out that way, even with the *printf
>>> *command.....???
>>>
>>> If anyone can offer some good suggestions about good formatting, that
>>> would be great.  I would really appreciate it.
>>>
>>> By the way, I did the same thing in Python and it took less than half as
>>> much code!  The Python code was short and to the point.  I guess Java has
>>> its uses, but for some things it is really tedious and overly complicated.
>>> Ah well.... but then again Java developers make really good money, so I
>>> guess I'll have to study both Java AND Python!
>>>
>>> Take care and thanks for the feedback.
>>>
>>> Best,
>>>
>>> Douglas Lewit
>>>
>>> _______________________________________________
>>> Chicago mailing list
>>> Chicago at python.org
>>> https://mail.python.org/mailman/listinfo/chicago
>>>
>>>
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20141010/bc129ee5/attachment.html>


More information about the Chicago mailing list