• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 13:50
CEST 19:50
KST 02: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
[ASL20] Ro24 Preview Pt1: Runway122v2 & SC: Evo Complete: Weekend Double Feature3Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18Serral wins EWC 202549
Community News
Maestros of The Game—$20k event w/ live finals in Paris1Weekly Cups (Aug 11-17): MaxPax triples again!10Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195Weekly Cups (Jul 28-Aug 3): herO doubles up6
StarCraft 2
General
RSL Revival patreon money discussion thread I made a 5.0.12/5.0.13 replay fix Geoff 'iNcontroL' Robinson has passed away #1: Maru - Greatest Players of All Time Is it ok to advertise SC EVO Mod streaming here?
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris Master Swan Open (Global Bronze-Master 2) $5,100+ SEL Season 2 Championship (SC: Evo) Sparkling Tuna Cup - Weekly Open Tournament RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below Mutation # 484 Magnetic Pull
Brood War
General
Flash Announces (and Retracts) Hiatus From ASL New season has just come in ladder BW General Discussion [ASL20] Ro24 Preview Pt1: Runway ASL 20 HYPE VIDEO!
Tourneys
Cosmonarchy Pro Showmatches [ASL20] Ro24 Group B [ASL20] Ro24 Group C [Megathread] Daily Proleagues
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Beyond All Reason Nintendo Switch Thread Total Annihilation Server - TAForever
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine European Politico-economics QA Mega-thread The Games Industry And ATVI
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
The Biochemical Cost of Gami…
TrAiDoS
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2236 users

The Big Programming Thread - Page 352

Forum Index > General Forum
Post a Reply
Prev 1 350 351 352 353 354 1031 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 6h 10m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SpeCial 273
Hui .143
Codebar 97
BRAT_OK 80
ProTech41
MindelVK 18
StarCraft: Brood War
Britney 36766
Bisu 2921
Jaedong 1225
EffOrt 501
ZerO 404
BeSt 388
Light 253
Stork 220
ggaemo 195
hero 189
[ Show more ]
Dewaltoss 135
Rush 117
Snow 95
Mind 82
sas.Sziky 54
sorry 46
Backho 30
Aegong 22
Rock 16
Sacsri 15
Terrorterran 15
scan(afreeca) 15
IntoTheRainbow 7
Dota 2
Gorgc8910
qojqva3441
XcaliburYe244
Counter-Strike
olofmeister581
Stewie2K177
Heroes of the Storm
Trikslyr60
Other Games
FrodaN1214
Beastyqt923
KnowMe141
ArmadaUGS112
markeloff71
QueenE69
ZerO(Twitch)16
Organizations
Other Games
BasetradeTV10
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• davetesta30
• Kozan
• sooper7s
• AfreecaTV YouTube
• Migwel
• LaughNgamezSOOP
• intothetv
• IndyKCrew
StarCraft: Brood War
• Pr0nogo 2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2977
League of Legends
• Jankos1533
• TFBlade924
Counter-Strike
• Shiphtur209
Other Games
• imaqtpie482
• WagamamaTV261
Upcoming Events
Online Event
6h 10m
The PondCast
16h 10m
WardiTV Summer Champion…
17h 10m
Zoun vs Bunny
herO vs Solar
Replay Cast
1d 6h
LiuLi Cup
1d 17h
BSL Team Wars
2 days
Team Hawk vs Team Dewalt
Korean StarCraft League
2 days
CranKy Ducklings
2 days
SC Evo League
2 days
WardiTV Summer Champion…
2 days
Classic vs Percival
Spirit vs NightMare
[ Show More ]
CSO Cup
2 days
[BSL 2025] Weekly
3 days
Sparkling Tuna Cup
3 days
SC Evo League
3 days
BSL Team Wars
4 days
Team Bonyth vs Team Sziky
Afreeca Starleague
4 days
Queen vs HyuN
EffOrt vs Calm
Wardi Open
4 days
Replay Cast
5 days
Afreeca Starleague
5 days
Rush vs TBD
Jaedong vs Mong
Afreeca Starleague
6 days
herO vs TBD
Royal vs Barracks
Liquipedia Results

Completed

Jiahua Invitational
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 1
SEL Season 2 Championship
WardiTV Summer 2025
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSLAN 3
CSL Season 18: Qualifier 2
CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
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 © 2025 TLnet. All Rights Reserved.