• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:50
CEST 22:50
KST 05:50
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244ByuL, and the Limitations of Standard Play3
Community News
Stellar Fest TWO the Moon (Dec 16-20)8Weekly Cups (August 24-30): Patches' balance mod takes over2New 3v3 BGH Ladder (and more) on ShieldBattery!40Weekly Cups (August 17-23): Zerg dominate the week6Weekly Cups (August 10-16): SHIN doubles4
StarCraft 2
General
Weekly Cups (August 10-16): SHIN doubles Nexon wins bid to develop StarCraft IP content, distribute Overwatch mobile game SC4ALL II: SC2 Player Announcement 6/8 - Maru Weekly Cups (August 24-30): Patches' balance mod takes over How would you feel about frequent/monthly balance patches for SC2?
Tourneys
2026 GSTL Announcement Stellar Fest TWO the Moon (Dec 16-20) PIG STY FESTIVAL 8.0! (13 - 23 August) Sparkling Tuna Cup - Weekly Open Tournament IntoTheTV X SOOP SC2 League : Weekly & Monthly
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 541 Binary Choice The PondCast: SC2 News & Results Mutation # 540 Dodge This Mutation # 539 Thunder Dome
Brood War
General
ASL22 General Discussion [Personal Project Share] Terran Defense v0.60 XUN appreciation thread Which box art did your first copy of StarCraft 1 have? BW General Discussion
Tourneys
[Megathread] Daily Proleagues BSL LAN Party - Kraków 29-30 August - OPEN SIGNUPS [ASL22] Ro24 Group F Small VOD Thread 2.0
Strategy
Replay Review Process - What do you do? Game Theory for Starcraft Odyssey Mineral Stack Saturation Fighting Spirit mining rates
Other Games
General Games
General RTS Discussion Thread Stratus: Battle for the sky now on steam Early acc Nintendo Switch Thread Stormgate/Frost Giant Megathread Anyone here play Quakeworld back in the day?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank TL Mafia Community Thread NeO.D_StephenKing vs This Guy From 1 Million Dance
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread European Politico-economics QA Mega-thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Regacy Esports: The Bh…
regacyesports
Violent Games and Crime Rate…
TrAiDoS
LOCKPICKING NOOB
LUCKY_NOOB
Cathedral Of CS And NY pizza a…
FuDDx
Please support my new stand…
Peanutsc
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3781 users

The Big Programming Thread - Page 352

Forum Index > General Forum
Post a Reply
Prev 1 350 351 352 353 354 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2013-09-12 23:56:27
September 12 2013 23:28 GMT
#7021
On September 13 2013 01:06 supereddie wrote:
Show nested quote +
On September 12 2013 10:34 berated- wrote:
Hmm. This seems like bad advice. Why would you want to take the time that your js works perfectly in every browser when most web devs are doing it for you by using jquery? Use a cdn, use gzip compression, its not that big.

This particular problem can be easliy solved with standard javascript that is supported in all browsers. There are no browser-specific functions needed - just standard javascript. You don't need external files, libraries etc. Every function is builtin in the javascript engine in a browser. It is complete overkill to use jQuery for this simple problem.


Absolutely, as well as many other problems if you look at them under a microscope. I think it's a big assumption to think that this will be the only problem you need to solve on a website.
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2013-09-13 02:21:24
September 13 2013 02:16 GMT
#7022
On September 13 2013 06:45 darkness wrote:
I was wondering how variables' scope is dealt with in regards to Java GUI. Is it global or do you need to declare everything as a field? All in all, how you deal with variables? Examples would be nice if you have nearby.


There are only a couple scopes for java and they all work the same whether you are doing a main method, server programming, or GUI programming, so I'm not quite sure why you specify in regards to GUI? Do you have an example of where the confusion comes in, that might be easier than people just coming up with examples for you.

Generally speaking your life will be better if you figure out how to develop without a dependence on static variables, unless the variables are truly static (like constants). It's not that statics are (all) bad, they generally just lead to harder to test code because of the lack of seams for dependency injection and can lead to trouble in multithreaded environments if you don't have a good understanding of what is happening.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-09-13 23:06:31
September 13 2013 22:51 GMT
#7023
On September 13 2013 11:16 berated- wrote:
Show nested quote +
On September 13 2013 06:45 darkness wrote:
I was wondering how variables' scope is dealt with in regards to Java GUI. Is it global or do you need to declare everything as a field? All in all, how you deal with variables? Examples would be nice if you have nearby.


There are only a couple scopes for java and they all work the same whether you are doing a main method, server programming, or GUI programming, so I'm not quite sure why you specify in regards to GUI? Do you have an example of where the confusion comes in, that might be easier than people just coming up with examples for you.

Generally speaking your life will be better if you figure out how to develop without a dependence on static variables, unless the variables are truly static (like constants). It's not that statics are (all) bad, they generally just lead to harder to test code because of the lack of seams for dependency injection and can lead to trouble in multithreaded environments if you don't have a good understanding of what is happening.


I'm just puzzled how variables are usually passed when it comes to Java GUI. Do you declare them as fields? Is that the general practice? Or via object references? Is MVC "the way to go" or simple stuff like class ButtonDemo_Extended from http://www.codeproject.com/Articles/33536/An-Introduction-to-Java-GUI-Programming good enough? Should I also use IDE to develop GUIs?
berated-
Profile Blog Joined February 2007
United States1134 Posts
September 14 2013 16:54 GMT
#7024
On September 14 2013 07:51 darkness wrote:
Show nested quote +
On September 13 2013 11:16 berated- wrote:
On September 13 2013 06:45 darkness wrote:
I was wondering how variables' scope is dealt with in regards to Java GUI. Is it global or do you need to declare everything as a field? All in all, how you deal with variables? Examples would be nice if you have nearby.


There are only a couple scopes for java and they all work the same whether you are doing a main method, server programming, or GUI programming, so I'm not quite sure why you specify in regards to GUI? Do you have an example of where the confusion comes in, that might be easier than people just coming up with examples for you.

Generally speaking your life will be better if you figure out how to develop without a dependence on static variables, unless the variables are truly static (like constants). It's not that statics are (all) bad, they generally just lead to harder to test code because of the lack of seams for dependency injection and can lead to trouble in multithreaded environments if you don't have a good understanding of what is happening.


I'm just puzzled how variables are usually passed when it comes to Java GUI. Do you declare them as fields? Is that the general practice? Or via object references? Is MVC "the way to go" or simple stuff like class ButtonDemo_Extended from http://www.codeproject.com/Articles/33536/An-Introduction-to-Java-GUI-Programming good enough? Should I also use IDE to develop GUIs?


I think all of these questions are dependent upon what you are trying to accomplish. There are always tradeoffs that you have to consider -- there isn't always a right or wrong answer, more of a what is best for my situation.

I personally do more java webapp development, so, I can't speak with 100% certainty, but MVC is a pattern that I enjoy using. It logically makes a lot of sense and allows for your code to be better modularized. Learning how to write that way would certainly extend past your current development.

As to whether the simple example is good enough, what are you trying to do? Are you the only one working on it? If so, then it's probably fine. The more complex that software gets, the more you are going to wish your code parts are a little less coupled so that you can get the amount of reuse and maintainability you are looking for. However, if you are never going to get to that level of complexity, why waste time setting up code infrastructure when you could have been done with the project much faster.

Do you want to use an IDE? The few times I've played with swing, I've just used netbeans because I have no vested interest in becoming an expert in it. I wanted to be able to do something quick and get it running, not so much learn all of the intricacies of everything.
Pawsom
Profile Blog Joined February 2009
United States928 Posts
September 14 2013 17:33 GMT
#7025
On September 12 2013 01:59 HardlyNever wrote:
Criticizing a working solution, without posting a better working solution, is definitely less constructive.



Dude if you take people criticizing your code so personally you're going to have a heart attack by the time you're 35.
TimKim0713
Profile Joined June 2012
Korea (South)221 Posts
September 14 2013 18:45 GMT
#7026
Hey guys,
I just basically started programming, but I have trouble understanding some minor things

-Parameters, (passing down?!, Why it's used, why not just use globally, which to me makes it easier/simpler?, how to apply in the method if used?, etc) When I look it up and try to understand online definition,examples, explanations, they are hard to understand...

-Use of "this.", "constructor", etc. (I feel like I'm really weak on method things T_T).
-All I know in java is... Scanner,loops, if statements, making method,calling them but without parameters(T_T), and alittle of arrays.
-At school we're just doing Karel the Robot things, At the moment, creating Ellipse Circle etc.

If you can answer this in a easy-understanding way it'd be awesome!
you can pm me or write here. Also if you can also have like 1:1 chat with me it'd be awesome too.
Thanks!
Millitron
Profile Blog Joined August 2010
United States2611 Posts
Last Edited: 2013-09-14 18:57:10
September 14 2013 18:51 GMT
#7027
On September 14 2013 07:51 darkness wrote:
Show nested quote +
On September 13 2013 11:16 berated- wrote:
On September 13 2013 06:45 darkness wrote:
I was wondering how variables' scope is dealt with in regards to Java GUI. Is it global or do you need to declare everything as a field? All in all, how you deal with variables? Examples would be nice if you have nearby.


There are only a couple scopes for java and they all work the same whether you are doing a main method, server programming, or GUI programming, so I'm not quite sure why you specify in regards to GUI? Do you have an example of where the confusion comes in, that might be easier than people just coming up with examples for you.

Generally speaking your life will be better if you figure out how to develop without a dependence on static variables, unless the variables are truly static (like constants). It's not that statics are (all) bad, they generally just lead to harder to test code because of the lack of seams for dependency injection and can lead to trouble in multithreaded environments if you don't have a good understanding of what is happening.


I'm just puzzled how variables are usually passed when it comes to Java GUI. Do you declare them as fields? Is that the general practice? Or via object references? Is MVC "the way to go" or simple stuff like class ButtonDemo_Extended from http://www.codeproject.com/Articles/33536/An-Introduction-to-Java-GUI-Programming good enough? Should I also use IDE to develop GUIs?

Unless its a totally trivial GUI, you usually write event handlers using anonymous inner classes. When you instantiate the event handler, it gets linked to a particular control in your UI (p.addActionListener(...) in this case), and when the event occurs, the code in the event handler gets triggered. This code can usually pass variables around like any other code.

This code declares an Action Listener which handles opening a file browser for a Sudoku game I built for a college project. The program was written MVC-style, this is a snippet from the Controller. The vairable "storedBoard" is the Model, which is basically just a big string representing the current state of the puzzle. When the "Open" menu item is chosen, a standard Java file browser is opened, the user picks a file, and assuming that nothing goes wrong (broken file or whatever), that file gets passed to the Model via the loadFile(File) method. "storedBoard.emptyStacks();" resets the undo/redo feature for the newly loaded puzzle.

p = new JMenuItem("Open");
p.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
storedBoard.getModel().stop();
String filename = File.separator+"tmp";
JFileChooser fc = new JFileChooser(directory);

fc.showOpenDialog(boardFrame);
File selFile = fc.getSelectedFile();
if (selFile != null)
{
storedBoard.loadFile(selFile);
storedBoard.emptyStacks();
}
}
});


There's about a dozen more of these little snippets in my program, each one calling different methods in the Model or View depending one what menu item it handles. I provided visibility to both the Model and the View first thing at run-time. My Main method was a separate class that simply instantiated the Model, and the View, then passed them both to the Controller via the constructor. The Controller just stores them as class variables.
Who called in the fleet?
DeltaX
Profile Joined August 2011
United States287 Posts
Last Edited: 2013-09-14 19:33:23
September 14 2013 19:28 GMT
#7028
On September 15 2013 03:45 TimKim0713 wrote:
Hey guys,
I just basically started programming, but I have trouble understanding some minor things

-Parameters, (passing down?!, Why it's used, why not just use globally, which to me makes it easier/simpler?, how to apply in the method if used?, etc) When I look it up and try to understand online definition,examples, explanations, they are hard to understand...


Using global variables like this is generally considered bad because when programs start to get big, it is hard to keep track of them all. This could lead to a situation where you accidentally reuse some global variable somewhere, and it will be a huge pain to track down why a problem is happening. Parameters avoid this by having what you call a scope, you can access them only inside the function, when the function ends/returns, they will go away, and they are all declared at the top of each function which tells you right away what you have to work with in case someone else wrote the code.

Global variables can be nice in small programs, but they can make writing even slightly complicated things a pain.


-Use of "this.", "constructor", etc. (I feel like I'm really weak on method things T_T).

"this" is used to refer to the current object. Say you have an apple class and an apple named myApple. If you were to call a function pick(), you could do myApple.pick(); But what if you were in that pick function and wanted to pass the object "myApple" to some other function of a different class? You could do myOtherObject.otherFunction(this); to pass it. There are other uses of "this" where you use it to increase readability and make clear what functions or variables you are refering to as well such as calling a second apple function inside of the first apple function, or accessing the object's variables inside a function.

A constructor is how you create a new object. When you want to make a new object, the constructor is what the program will look for to know how to create that new object.

If you just started a CS class, this stuff may not have been fully explained yet so I hope I have not confused you. Overall I found writing code to be the best way to understand how these things worked and why I would want to use them.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
Last Edited: 2013-09-14 20:48:31
September 14 2013 20:34 GMT
#7029
On September 15 2013 03:45 TimKim0713 wrote:
-Parameters, (passing down?!, Why it's used, why not just use globally, which to me makes it easier/simpler?, how to apply in the method if used?, etc) When I look it up and try to understand online definition,examples, explanations, they are hard to understand...


In small projects, yes, parameters seem to be a hassle. However, once a program becomes bigger, it becomes important to know when things happen, e.g. when and where a variable was set to a value, when a database connection was established, etc.
With globals, a function never knows if all the variables really exist and a programmer using a function never knows what variables that function actually changes. You can't always go through all functions you use and check what they really access, so by using parameters and no global variables, you always know that it only affects what you give it to affect, nothing more. You don't have any sudden side effects messing with the rest of the program.

Every function should always just be dependant on the parameters it is given (and class variables it has access to) and otherwise be independent from the environment it is run in since it's often very helpful to run a function on it's own to test for problems, even without explicit unit tests, and if you first need to initialize a state you can't know without first digging into the function, creating such independent tests becomes a huge problem.

We have a similar situation in the company i just started working in. The code heavily relies on singletons, which look like objects but are actually sort of global variables with lazy loading and while some of the developers would love to add unit tests, it's simply impossible because almost every method is dependant on other code running first and you can't set up any test without first running basically the whole project first and it's almost impossible to refactor it into a better form.



"this.", constructors, destructors, etc. are fairly simple to understand once you understand the reasoning behind it. In modern programming, the above mentioned independency of functions is a core idea that is also used for methods and classes.

A class should always be in a valid state, meaning if you need to run it's methods in a specific order, it's poorly programmed and a trap for any future programmer working with it. A constructor serves to set up a valid state by taking all neccessary parameters to get it into that state and then doing the neccessary initialization so other methods don't have to check the state every time they are called.

Class variables are accessible to all methods in the class, so it's easy to accidently use a variable name used in the class a second time in a method. To avoid conflicts, the "this" keyword makes sure even if you accidently used a variable name twice, it uses the one you meant to use, i.e. the one from the class, not the one inside the method. As an example, if your class does something with a "CustomerList", it might have a parameter "customerList" in the constructor and a class variable "customerList" and to set the class variable in the constructor, you can simply do "this.customerList = customerList". Personally, i strongly recommend always using this when accessing class variables, even when whatever language you use doesn't explicitely require it, just to avoid future pitfalls. With most IDEs it's not even more to type.
TimKim0713
Profile Joined June 2012
Korea (South)221 Posts
September 14 2013 23:11 GMT
#7030
@DeltaX and Morfildur,
thank you so much!
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-09-15 00:01:27
September 15 2013 00:00 GMT
#7031
On September 15 2013 03:51 Millitron wrote:
Show nested quote +
On September 14 2013 07:51 darkness wrote:
On September 13 2013 11:16 berated- wrote:
On September 13 2013 06:45 darkness wrote:
I was wondering how variables' scope is dealt with in regards to Java GUI. Is it global or do you need to declare everything as a field? All in all, how you deal with variables? Examples would be nice if you have nearby.


There are only a couple scopes for java and they all work the same whether you are doing a main method, server programming, or GUI programming, so I'm not quite sure why you specify in regards to GUI? Do you have an example of where the confusion comes in, that might be easier than people just coming up with examples for you.

Generally speaking your life will be better if you figure out how to develop without a dependence on static variables, unless the variables are truly static (like constants). It's not that statics are (all) bad, they generally just lead to harder to test code because of the lack of seams for dependency injection and can lead to trouble in multithreaded environments if you don't have a good understanding of what is happening.


I'm just puzzled how variables are usually passed when it comes to Java GUI. Do you declare them as fields? Is that the general practice? Or via object references? Is MVC "the way to go" or simple stuff like class ButtonDemo_Extended from http://www.codeproject.com/Articles/33536/An-Introduction-to-Java-GUI-Programming good enough? Should I also use IDE to develop GUIs?

Unless its a totally trivial GUI, you usually write event handlers using anonymous inner classes. When you instantiate the event handler, it gets linked to a particular control in your UI (p.addActionListener(...) in this case), and when the event occurs, the code in the event handler gets triggered. This code can usually pass variables around like any other code.

This code declares an Action Listener which handles opening a file browser for a Sudoku game I built for a college project. The program was written MVC-style, this is a snippet from the Controller. The vairable "storedBoard" is the Model, which is basically just a big string representing the current state of the puzzle. When the "Open" menu item is chosen, a standard Java file browser is opened, the user picks a file, and assuming that nothing goes wrong (broken file or whatever), that file gets passed to the Model via the loadFile(File) method. "storedBoard.emptyStacks();" resets the undo/redo feature for the newly loaded puzzle.

p = new JMenuItem("Open");
p.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
storedBoard.getModel().stop();
String filename = File.separator+"tmp";
JFileChooser fc = new JFileChooser(directory);

fc.showOpenDialog(boardFrame);
File selFile = fc.getSelectedFile();
if (selFile != null)
{
storedBoard.loadFile(selFile);
storedBoard.emptyStacks();
}
}
});


There's about a dozen more of these little snippets in my program, each one calling different methods in the Model or View depending one what menu item it handles. I provided visibility to both the Model and the View first thing at run-time. My Main method was a separate class that simply instantiated the Model, and the View, then passed them both to the Controller via the constructor. The Controller just stores them as class variables.


Yeah, I've checked some MVC code and I like how the constructor is used in this case. However, what does this mean?

storedBoard.getModel().stop();


Variable.method.method?


dae
Profile Joined June 2010
Canada1600 Posts
September 15 2013 00:11 GMT
#7032

Yeah, I've checked some MVC code and I like how the constructor is used in this case. However, what does this mean?

storedBoard.getModel().stop();


Variable.method.method?




What it means is that storedBoard.getModel() is returning an Object, on which he is calling the stop method of. This is probably a variable of storedBoard called Model.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2013-09-15 00:17:03
September 15 2013 00:15 GMT
#7033
--- Nuked ---
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
September 15 2013 00:23 GMT
#7034
On September 15 2013 09:11 dae wrote:
Show nested quote +

Yeah, I've checked some MVC code and I like how the constructor is used in this case. However, what does this mean?

storedBoard.getModel().stop();


Variable.method.method?




What it means is that storedBoard.getModel() is returning an Object, on which he is calling the stop method of. This is probably a variable of storedBoard called Model.


Right, thanks. Is this considered 'ok to use'? Isn't it less readable if you skip a line or two like that?

For example, isn't this slightly more readable:

Object thatReturnedObject;

thatReturnedObject = storedBoard.getModel();
thatReturnedObject.stop();
Cyx.
Profile Joined November 2010
Canada806 Posts
September 15 2013 00:31 GMT
#7035
On September 15 2013 09:23 darkness wrote:
Show nested quote +
On September 15 2013 09:11 dae wrote:

Yeah, I've checked some MVC code and I like how the constructor is used in this case. However, what does this mean?

storedBoard.getModel().stop();


Variable.method.method?




What it means is that storedBoard.getModel() is returning an Object, on which he is calling the stop method of. This is probably a variable of storedBoard called Model.


Right, thanks. Is this considered 'ok to use'? Isn't it less readable if you skip a line or two like that?

For example, isn't this slightly more readable:

Object thatReturnedObject;

thatReturnedObject = storedBoard.getModel();
thatReturnedObject.stop();


Generally it's just a bit aggravating writing three lines where you could be doing one, and most people who've worked in an OO language for a little while will understand that a method called getX is probably just returning you the object X. It doesn't hurt your clarity that much at all.
snpnx
Profile Joined February 2010
Germany454 Posts
September 15 2013 11:22 GMT
#7036
On September 15 2013 09:31 Cyx. wrote:
Show nested quote +
On September 15 2013 09:23 darkness wrote:
On September 15 2013 09:11 dae wrote:

Yeah, I've checked some MVC code and I like how the constructor is used in this case. However, what does this mean?

storedBoard.getModel().stop();


Variable.method.method?




What it means is that storedBoard.getModel() is returning an Object, on which he is calling the stop method of. This is probably a variable of storedBoard called Model.


Right, thanks. Is this considered 'ok to use'? Isn't it less readable if you skip a line or two like that?

For example, isn't this slightly more readable:

Object thatReturnedObject;

thatReturnedObject = storedBoard.getModel();
thatReturnedObject.stop();


Generally it's just a bit aggravating writing three lines where you could be doing one, and most people who've worked in an OO language for a little while will understand that a method called getX is probably just returning you the object X. It doesn't hurt your clarity that much at all.


Adding to this: If you're intending to use the object for quite a while (call multiple of its functions etc. afterwards) it might be better to read using the temporary variable to interact with it. But in a case where you only call 1 or 2 methods it's clear what you mean if you use the short form.
"Language is Freeware, in that it's free to use, but it's not Open Source, so you can't just change things how you like."
artynko
Profile Joined November 2010
Slovakia86 Posts
September 15 2013 14:30 GMT
#7037
On September 15 2013 09:23 darkness wrote:
Show nested quote +
On September 15 2013 09:11 dae wrote:

Yeah, I've checked some MVC code and I like how the constructor is used in this case. However, what does this mean?

storedBoard.getModel().stop();


Variable.method.method?




What it means is that storedBoard.getModel() is returning an Object, on which he is calling the stop method of. This is probably a variable of storedBoard called Model.


Right, thanks. Is this considered 'ok to use'? Isn't it less readable if you skip a line or two like that?

For example, isn't this slightly more readable:

Object thatReturnedObject;

thatReturnedObject = storedBoard.getModel();
thatReturnedObject.stop();

The readability depends on the particular method where it is used it may well be that storeBoard.getModel().stop() is more readable since you don't have to track out what the thatReturnedObject is as in the second example, if the get call was way earlier in the method.

Also what people that learn to program dont realize is that when you start to work you end up writing THOUSANDS and thousands of lines of code, and if I have to type 3 lines instead of one over months time spending writing those useless lines could be spend doing something else. This is why people that go from java to scala for example feel more productive since the language allows you to do more with less sytax.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
September 15 2013 17:43 GMT
#7038
Alright. Thank you for explanation.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-09-15 18:43:47
September 15 2013 18:39 GMT
#7039
I've been wondering how one can keep record of unlimited number of users in a struct way fashion in Java.

For example,


class Person {
private String name;
private String surname;
private int age;

Person(String name, String surname, int age) {
this.name = name;
this.surname = surname;
this.age = age;
}

// some getter methods
public int getAge() {
return age;
}

// etc... and setter methods too
public void setAge(int age) {
this.age = age;
}
}


I know I can have a single record by having:

Person bill = new Person("Bill", "Gates", 57);

How can I have an unlimited number of people though? Is it possible without creating individual objects manually?
WolfintheSheep
Profile Joined June 2011
Canada14127 Posts
September 15 2013 18:57 GMT
#7040
On September 16 2013 03:39 darkness wrote:
I've been wondering how one can keep record of unlimited number of users in a struct way fashion in Java.

For example,


class Person {
private String name;
private String surname;
private int age;

Person(String name, String surname, int age) {
this.name = name;
this.surname = surname;
this.age = age;
}

// some getter methods
public int getAge() {
return age;
}

// etc... and setter methods too
public void setAge(int age) {
this.age = age;
}
}


I know I can have a single record by having:

Person bill = new Person("Bill", "Gates", 57);

How can I have an unlimited number of people though? Is it possible without creating individual objects manually?

Use an array (or, for your purposes, an ArrayList would probably be more suitable because). Technically not "unlimited" because of hard-coded limitations on integer size, but unless you're planning to have a couple of billion entries it's not something you generally have to plan for.

Unless I've completely mistaken your question.
Average means I'm better than half of you.
Prev 1 350 351 352 353 354 1032 Next
Please log in or register to reply.
Live Events Refresh
RotterdaM Event
16:15
Rotti's PatchesSC Open #2
RotterdaM903
TKL 250
IndyStarCraft 234
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 903
TKL 250
IndyStarCraft 234
ZombieGrub40
StarCraft: Brood War
Shuttle 798
Horang2 199
Dewaltoss 112
Terrorterran 45
Dota 2
syndereN254
NeuroSwarm98
LuMiX1
League of Legends
Doublelift3280
JimRising 286
Counter-Strike
shoxiejesuss1779
Other Games
Grubby2130
fl0m1075
C9.Mang0245
ArmadaUGS105
KnowMe73
Chillindude20
kaitlyn0
Organizations
StarCraft 2
WardiTV757
Other Games
BasetradeTV27
[ Show 14 non-featured ]
StarCraft 2
• RyuSc2 11
• Adnapsc2 3
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21356
Other Games
• imaqtpie1194
• Scarra882
• Shiphtur185
Upcoming Events
Replay Cast
3h 10m
The PondCast
13h 10m
OSC
1d 1h
IntoTheTV X SOOP
1d 14h
CranKy Ducklings
2 days
Sparkling Tuna Cup
3 days
OSC
3 days
Shopify Rebellion Sundays
3 days
Mixu vs TBD
Spirit vs TBD
Clem vs TBD
Afreeca Starleague
4 days
Soma vs Shuttle
BeSt vs Rush
WardiTV Weekly
4 days
[ Show More ]
Afreeca Starleague
5 days
Leta vs ggaemo
Jaedong vs Queen
GSL
5 days
PiGosaur Cup
6 days
Kung Fu Cup
6 days
Liquipedia Results

Completed

KCM Special KOR vs CHN
PiG Sty Festival 8.0
Light Tournament 2026

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
RSL Revival: Season 6
Calamity Invitational
Big Dog Cup 2026 Div 1
BLAST Open Fall 2026
Esports World Cup 2026
Esports World Cup 2026: LCQ
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026

Upcoming

Acropolis #5
Acropolis #5 - TRS
Escore Tournament S3: King of Kings
Blizzard Classic Cup 2026
Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.