Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS201 Introduction to Programming GDB No.1 Solutions and Discussions Spring 2014
#1
[SIZE="3"]CS201 Introduction to Programming GDB No.1 Solutions and Discussions Spring 2014 Due Date 8th August 2014[/SIZE]

[SIZE="3"]GDB topic:
Is it more expensive to use too many static variables instead of ordinary variables? If yes, then how?
Your answer must be concise and not be more than 200 words.[/SIZE]
Reply
#2
It's not a problem. However, it is generally accepted good design practice to limit the scope of every variable so that it's as wide as it needs to be - but no wider ;-)

This means that:
- you don't use a method local variable as the controlled variable of a for loop, if you can declare the controlled variable in the for loop heading.
- you don't use a class global variable (field) inside a method if you can instead use a local variable declared inside the method.
- you don't declare a field public if it can be protected, nor protected if it can be private.
- you don't declare a field static if it can be non-static.
- class level "final" values should be declared static.

In my experience as a Java programming teacher, most students have difficulties with the second option, and will tend to declare a lot of class global fields for variables should have been declared local.

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#3
Static variables represent global state. That's hard to reason about and hard to test: if I create a new instance of an object, I can reason about its new state within tests. If I use code which is using static variables, it could be in any state - and anything could be modifying it.

I could go on for quite a while, but the bigger concept to think about is that the tighter the scope of something, the easier it is to reason about. We're good at thinking about small things, but it's hard to reason about the state of a million line system if there's no modularity. This applies to all sorts of things, by the way - not just static variables.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HRM628 VU Current GDB No. 1 Spring April 2012 Solution required Vuhelper 1 3,674 07-22-2020, 08:06 PM
Last Post: Johnnieaunders
  MGT501 Human Resource Management GDB No.1 Discussions and Solutions Fall 2014 Vuhelper 0 3,508 12-04-2014, 09:07 PM
Last Post: Vuhelper
  MGT211 Introduction To Business GDB No 1 Solution Ideas Fall 2014 Vuhelper 0 1,667 12-04-2014, 03:20 PM
Last Post: Vuhelper
  FIN711 Advanced Financial Accounting GDB No. 01 Fall 2014 Last Date 8th December Vuhelper 0 2,079 12-03-2014, 09:15 PM
Last Post: Vuhelper
  MGT101 Financial Accounting GDB Solution and Discussion December 2014 Vuhelper 0 2,861 12-03-2014, 09:05 PM
Last Post: Vuhelper
  MGT703 Strategic Management GDB No.1 Fall 2014 Solutions Ideas Vuhelper 0 1,846 12-03-2014, 08:45 PM
Last Post: Vuhelper
  MGT201 Financial Management GDB No. 01 Solution Fall 2014 Last date is 4th Dec 2014 Vuhelper 0 2,474 12-03-2014, 03:58 PM
Last Post: Vuhelper
  MGT520 International Business GDB No. 01 Solution and Discussion Fall 2014 viki 0 2,586 12-03-2014, 03:03 PM
Last Post: viki
  GDB No 1 MGT301 Principles of Marketing Solution and Discussion December Fall 2014 viki 0 2,506 12-03-2014, 02:45 PM
Last Post: viki
  MGT602 Entrepreneurship GDB No 1 Discussion and Solution Fall 2014 Vuhelper 0 2,478 12-02-2014, 10:36 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)