aspose file tools*
The moose likes Cattle Drive and the fly likes Say 4b, Static vs Instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Say 4b, Static vs Instance" Watch "Say 4b, Static vs Instance" New topic
Author

Say 4b, Static vs Instance

Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1360
    
  17
Hi,

I've constructed two versions of Say 4b (tell a lie... I have made five different versions with three different main types of approach, but I will not bore you with the details!) and it got me wondering...

How have you approached this conceptually?

Have you made everything static - methods, variables, arrays - and then passed the required information back and forth?

Or have you kept only certain key portions static and made the rest non-static?

Are there clear advantages/disadvantages either way?

What about the passing of arguments and returning types? Do you tend to toss stuff back and forth, or do you store it in variables outside the methods and then update this?

Do personal preferences come into play, or are there 'java best practices' that emerge with a bit of experience?

I'm not looking for actual code or solutions or anything like this, I am just curious about the "basic principles" side of things.

Katrina
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Originally posted by Katrina Owen:
What about the passing of arguments and returning types? Do you tend to toss stuff back and forth, or do you store it in variables outside the methods and then update this?

Do personal preferences come into play, or are there 'java best practices' that emerge with a bit of experience?


You might be interested in this previous thread regarding variables stored outside methods. And another thread on a similar topic.

The key is that although it doesn't seem to matter much in this small assignment, we want to build good multi-process-safe habits now.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
I've constructed two versions of Say 4b (tell a lie... I have made five different versions with three different main types of approach,

Now you are where Nick was so recently ...
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20572
    ∞

How have you approached this conceptually?

For teaching? I think there are a plethora of lessons in 4b. Of course, most of those lessons are a bit predictive: what students will try to that we can have certain nits to pick. Although many students get to a certain point and they start to see the nits themselves! It is within this assignment that the lessons learned from the previous assignments really start to pay off!

Have you made everything static - methods, variables, arrays - and then passed the required information back and forth?

There is a time and place for each. This assignment does not touch object oriented programming yet, so the solution should be (will be) procedural.

With procedural programming, one should avoid "global variables" - variables that are available to all methods. There are a list of reasons for this practice.

In fact - I'm gonna take the instructor's easy road here: Marilyn listed one reason why that I'm guessing is beyond most students working on this assignment. But there is a simpler reason .... can any of you tell me what it is?

Are there clear advantages/disadvantages either way?

Yes. You will learn more about that in later assignments.

What about the passing of arguments and returning types? Do you tend to toss stuff back and forth, or do you store it in variables outside the methods and then update this?

The answer to this question, as to almost all questions is: "it depends". Knowing where to store information is a big part of good engineering.

The general rule of thumb is to keep the scope as limited as possible. So you would try to have it be a method variable first. If that cannot work, then a parameter. If that cannot work, then a class attribute.

Do personal preferences come into play, or are there 'java best practices' that emerge with a bit of experience?

Yes and yes.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1360
    
  17
Hi Paul,

This is one of the most exciting aspects of the drive. Making a program that works is *not* the problem. Making it elegant is fun, making it readable is delightful and a relief to sore nerve endings from working on ugly, ugly code, but the real winnings are in starting to see the outline of the difference between reasonably okay programming practices and good, waterproof programming practices.

I hadn't even thought about multi-process until Marilyn mentioned it.

I try all sorts of things out, and I am always thinking about how these things fit together (while I eat, shower, take the bus, drink coffee)... I always have a pad for scribbling thoughts about how to solve things, but it is still all in my head, and my head has *not* been anywhere near good programming practices (well, apart from the last couple of weeks here at javaranch, of course).

One of the reasons that I was tempted to have class variables in the Say assignment is that I kept wanting to return two values, and figured that making an int[] array to hold those two variables was much too klunky.

I rethought the process so that I could make them method variables instead.

It seems as though the cattle drive is set up so that we *do* run into the types of conundrums that get us thinking about aspects of 'good practice' without overwhelming all the circuits. I really appreciate that!

Katrina
[ November 23, 2006: Message edited by: Katrina Owen ]
Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
Katrina, Marilyn, Pauline, Paul Hi!

I have just gone over the numerous attempts I made at 4b to see if there was a process.........

In every submission the code *worked*, however,

What I will do is list the attempts and try and give a general idea of the theme of the nitpicking. OK?

1st attempt - 1) style guide errors on my account. 2) Poor choice of method names, variables etc. 3) i.e. readability was poor ....

2nd attempt - 1) readability again - add blank lines and some issues with the indentation (not critical though) 2) Main method too busy.... 3) Inappropriate use of for loop.

3rd attempt - 1) too many 0000000's 2) spacing around casts 3) things in a method that get repeated & 4) of course readability......

4th attempt - 1) static vs instance!! 2) How about using parameters?

5th attempt - 1) Processing some values and then passing to a method, rather than letting the method do the work.

I interrupt this to say this is where I posted my say4b completely stumped post!!

I got a very helpful reply.........(in fact a few)

6th attempt - complete rubbish!!!

At this point I decided my OS was at fault

I decided to install linux and on my next attempt I got the

Hope this helps

Nick
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Originally posted by Nick White:
At this point I decided my OS was at fault

I decided to install linux and on my next attempt I got the



LOL
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6


Gotta love this place.
Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
So in answer to anyone who struggles with Say4b the answer............

ubuntu in my case!

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20572
    ∞

Katrina,

I did spend a lot of time coming up with the first dozen assignments. I wanted them to not only teach and to teach more through nitpicking (because almost everybody will make the same mistakes), but I wanted them to be interesting - for those that have done programming before and those that have not. The first dozen assignments are truly the very beginning of what is now JavaRanch. They are the first bits of Java that I put up on the internet for public consumption because I thought I had stumbled onto something really worth of the mighty internet. And then I set about polishing them for months.

Marilyn has done a fantastic job of enhancing them, adding to them and organizing them.

Returning multiple things: At this point, that should not be a concern. When you move into OO programming, that would be a good thing to explore - returning an object that contains two objects.

Nick, Do *you* think that your final attempt was better than your first? And (back on topic) do you think that the assignment was designed for you to make those very mistakes? Do you think that almost everybody else made a lot of the same mistakes?
Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
Paul responded: Nick, Do *you* think that your final attempt was better than your first? And (back on topic) do you think that the assignment was designed for you to make those very mistakes? Do you think that almost everybody else made a lot of the same mistakes?


Without any doubt my final response was "better". Why? Even to me, it looked cleaner, probably was more efficient, and after gaining further understanding it was obviously better.

However. I have NEVER used java before I started the cattle drive. In fact I have NEVER programmed at all! I have though used small scripts, had a vague understanding of computer programming (if you will excuse my terminology ), but that is a different off topic discussion.

I hadn't really thought about the design of the assignment - I have just accepted that there are people out there with great knowledge, who are prepared to give their time and energy to helping others learn - and I truly thank you all for that. It still amazes me, - and the $200 is, to me at least almost insignificant, but still gives the incentive if you understand what I mean?

Now to the solution....

I expect, although I have no idea really, that people before me have made the same mistakes. I think it is great that I don't really know. Why? Because it means that everyone who has gone through it has valued the ethos of not disclosing the 'solution' - this holds for any code related queries across javaranch - again I commend you ALL for this.

If truth be told, once I received the 'instructors' solution, I actually thought *MINE* was more readable!!! (All thanks to the ladies I hasten to add).

I am in touch with another rancher -and we are going to share our solutions, BUT only after each of us getting the pass required. This then gives us not only OUR solution, but also the instructors solution and then each others - I bet all three will be different - but this can surely only help us?

If this isn't the way to go - tell me now and I will refrain!

After this rambling - and you can tell that this project means a lot to me - I thank you once more - keep up the excellent work, and if I could help I would try.

Regards

Nick
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20572
    ∞

Share all ya want! If anybody gets anything before they should, they just get less of an education and the nitpickers lives are a little easier!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Say 4b, Static vs Instance