• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:58
CEST 15:58
KST 22:58
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)48Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) [D] Wireframe Casting Removed Clem: "I don't have that much hope in Blizzard" Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken?
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
ASL22 General Discussion BW General Discussion Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) Etiquete rules in Asl? Recent recommended BW games
Tourneys
[Megathread] Daily Proleagues Escore Tournament - Season 3 Small VOD Thread 2.0 [IPSL] Spring 2026 Grand Finals - This Weekend!
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Path of Exile General RTS Discussion Thread Nintendo Switch Thread Beyond All Reason Stormgate/Frost Giant Megathread
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread The Games Industry And ATVI Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7201 users

The Big Programming Thread - Page 426

Forum Index > General Forum
Post a Reply
Prev 1 424 425 426 427 428 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.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
January 14 2014 02:39 GMT
#8501
On January 14 2014 10:09 WarSame wrote:
Show nested quote +
On January 14 2014 07:52 sluggaslamoo wrote:
On January 13 2014 11:04 WarSame wrote:
Hey everyone, I finished my Pong game now! This time around I tried to obey Sluggaslamoo and Darkness and make it into a MVC project with clear and small methods. In general, I think I've done so correctly. The only thing that really stands out to me as a potential non-error downside is that when you press Space and are trying to move your paddle at the same time it sometimes stops your paddle. Also, I did a non-decorated Window because the borders were messing up the display. Paddles and the ball would go through the bottom border where they weren't visible, which caused problems.

The link is: https://github.com/WarSame/PongGraeme

EDIT: It contains an executable JAR if you feel like checking it out. Runs right out of the box. Don't need to download anything other than the JAR.


Its much better than your first so well done.

However its not really MVC as there are no models.

Make sure to create a class for each component in your project. Not because its MVC but because of OOP, object decomposition is fundamental to OOP. If you aren't decomposing your project into separate objects, then you may as well not be using Java .

You don't really need to think too hard about it either. What does a Ping Pong game consist of? Think about that, then make the appropriate classes and place the logic there.

Your code would be ok if it was written in a non-OO language though.

Thanks for the feedback. For MVC I thought that View = user display, Model = data, Control = controlling logic. As I saw it the Model was PongData, the View was PongPanel and the Control was PongFrame. I guess I really misunderstood what MVC is. Looking at Wikipedia this seems like it might be an example of a passive model, though, where the view is updated from the model by polling(by running the heartbeat cycle with sleep lengths). Maybe not, and honestly this is confusing me quite a bit by this point. Could you point out what you believe would make this into an MVC project?

As for making a class for each component of the project, I'm not really sure what you mean by that. Do you mean I should make one for Ball(with an X and Y value/speed), one for Paddle, and so on like that? If so, you are definitely right and I regret not doing that. If not could you please clarify it? And thanks for the feedback throughout, I definitely appreciate it. This project was a lot easier to handle organization-wise than the last one for Tic Tac Toe.


Yep basically what you said and not much more than that if at all. Those classes will basically serve as "models".

Controllers handle inputs. For example in a website it will handle the URL's, in your case its the game controller inputs. There should be minimal logic in the controller. Think about how much logic is in an actual game controller, it takes a signal, and converts it into an instruction to the game, that's all your controller should do as well. As a rule of thumb, light controllers, fat models.

Pretty much all the logic should be in your models. Anything code that has anything to do with a model, should be in the model itself. For example, "moving a Paddle", there should be a move method on the Paddle itself, don't write the logic in the controller or anywhere else. In the controller you would handle the mouse movement, and delegate all logic to the Paddle by passing in the mouse event or minimal information necessary.

You could also do it declaratively, by adding in a listener to the paddle in the beginning and firing it off with the controller.

When I was saying that your last example was MVC, I was more or less being tongue in cheek about MVC not being the issue there. When you do things properly your program will naturally become MVC of sorts. Even when you do implement what I said, it won't be MVC really.

MVC normally has an ORM associated with it, and you declare Models as an abstraction for saveable/stateful components in your application.

I only pointed it out because you specifically wanted your app to be MVC. I don't think its necessary to think of it like that though. MVC is much more useful for applications where you need to save state. This is more or less focused on doing Responsibility Driven Design.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
phar
Profile Joined August 2011
United States1080 Posts
January 14 2014 02:41 GMT
#8502
On January 14 2014 10:30 sob3k wrote:
If I want to add H1-H6 headers to a previously made page for SEO purposes, if there any way for me to remove all formatting from them? I just want to stick them on as SEO markers and not have them effect the site visibly at all. Right now they break all kinds of stuff. I tried some resets but none of them reduce the headings to just tags.

I'm gonna avoid commenting on whether or not you should be doing that for SEO purposes, but have you looked at the page's css at all? That should be controlling the way stuff looks, not so much your html.
Who after all is today speaking about the destruction of the Armenians?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
January 14 2014 02:58 GMT
#8503
MVC isn't about the existence of classes and pinging the models, it's about how the classes are bound together, and how classes access and receive updates from each other. If you have to keep a reference to the model in your view, you have broken MVC. Throughout both your Frame and DisplayPanel classes, you keep a local private copy of variables from your Data, and things like having your initializeData method inside your Frame class. You haven't separated how the Model, View and Controller interact with each other. You still modify data values outside of the data class.
There is no one like you in the universe.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2014-01-14 03:00:56
January 14 2014 02:59 GMT
#8504
On January 14 2014 11:39 sluggaslamoo wrote:
Show nested quote +
On January 14 2014 10:09 WarSame wrote:
On January 14 2014 07:52 sluggaslamoo wrote:
On January 13 2014 11:04 WarSame wrote:
Hey everyone, I finished my Pong game now! This time around I tried to obey Sluggaslamoo and Darkness and make it into a MVC project with clear and small methods. In general, I think I've done so correctly. The only thing that really stands out to me as a potential non-error downside is that when you press Space and are trying to move your paddle at the same time it sometimes stops your paddle. Also, I did a non-decorated Window because the borders were messing up the display. Paddles and the ball would go through the bottom border where they weren't visible, which caused problems.

The link is: https://github.com/WarSame/PongGraeme

EDIT: It contains an executable JAR if you feel like checking it out. Runs right out of the box. Don't need to download anything other than the JAR.


Its much better than your first so well done.

However its not really MVC as there are no models.

Make sure to create a class for each component in your project. Not because its MVC but because of OOP, object decomposition is fundamental to OOP. If you aren't decomposing your project into separate objects, then you may as well not be using Java .

You don't really need to think too hard about it either. What does a Ping Pong game consist of? Think about that, then make the appropriate classes and place the logic there.

Your code would be ok if it was written in a non-OO language though.

Thanks for the feedback. For MVC I thought that View = user display, Model = data, Control = controlling logic. As I saw it the Model was PongData, the View was PongPanel and the Control was PongFrame. I guess I really misunderstood what MVC is. Looking at Wikipedia this seems like it might be an example of a passive model, though, where the view is updated from the model by polling(by running the heartbeat cycle with sleep lengths). Maybe not, and honestly this is confusing me quite a bit by this point. Could you point out what you believe would make this into an MVC project?

As for making a class for each component of the project, I'm not really sure what you mean by that. Do you mean I should make one for Ball(with an X and Y value/speed), one for Paddle, and so on like that? If so, you are definitely right and I regret not doing that. If not could you please clarify it? And thanks for the feedback throughout, I definitely appreciate it. This project was a lot easier to handle organization-wise than the last one for Tic Tac Toe.


Yep basically what you said and not much more than that if at all. Those classes will basically serve as "models".

Controllers handle inputs. For example in a website it will handle the URL's, in your case its the game controller inputs. There should be minimal logic in the controller. Think about how much logic is in an actual game controller, it takes a signal, and converts it into an instruction to the game, that's all your controller should do as well. As a rule of thumb, light controllers, fat models.

Pretty much all the logic should be in your models. Anything code that has anything to do with a model, should be in the model itself. For example, "moving a Paddle", there should be a move method on the Paddle itself, don't write the logic in the controller or anywhere else. In the controller you would handle the mouse movement, and delegate all logic to the Paddle by passing in the mouse event or minimal information necessary.

You could also do it declaratively, by adding in a listener to the paddle in the beginning and firing it off with the controller.

When I was saying that your last example was MVC, I was more or less being tongue in cheek about MVC not being the issue there. When you do things properly your program will naturally become MVC of sorts. Even when you do implement what I said, it won't be MVC really.

MVC normally has an ORM associated with it, and you declare Models as an abstraction for saveable/stateful components in your application.

I only pointed it out because you specifically wanted your app to be MVC. I don't think its necessary to think of it like that though. MVC is much more useful for applications where you need to save state. This is more or less focused on doing Responsibility Driven Design.

Awesome, thanks!

EDIT: Blisse, my view doesn't contain a model. It only gets the values of the objects and then displays those. Maybe that's what you meant.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2014-01-14 03:14:51
January 14 2014 03:13 GMT
#8505
You have multiple sections in your View and Controller where you have things like

+ Show Spoiler +



//Frame/game data
private static boolean gameWon;
private static boolean pointScored;
private static final int maxPoints = PongData.getMaxPoints();
private static final int paddleChange = PongData.getPaddleChange();
private static int frameHeight;
private static int frameWidth;
private static final int paddleHeight = PongData.getPaddleHeight();
private static final int paddleWidth = PongData.getPaddleWidth();
private static KeyEvent e;

//Ball data
private static final int updateTime = 16;//Use this to lower/raise the rate of refresh on the ball and AI. ms. Currently at 60fps
private static int ballXLocation;
private static int ballYLocation;
private static int ballXSpeed;
private static int ballYSpeed;
private static int ballXInitialSpeed;
private static int ballYInitialSpeed;
private static final double ballSpeedIncrease = 1.1;//Ratio of how fast the ball speeds up on collisions.

//Player data
private static final int playerPaddleXLocation = PongData.getPlayerPaddleXLocation();
private static int playerPaddleYLocation;
private static int playerScore;
private static boolean keyDown;
private static boolean keyUp;

//Ai data
private static final int aiPaddleXLocation = PongData.getAiPaddleXLocation();
private static int aiPaddleYLocation;
private static int aiScore;




Why do you have static private references to properties of your model inside your views and controllers?

You even label these properties as "data".

If you need to keep references like so, you are breaking how MVC works. MVC is supposed to simplify how your View interacts with your Models. Each View should simply get the required properties from the Model, then transform it a bit before displaying to the user. Not keep its value as a class property. Re-writing those properties inside each outer class defeats the entire point of MVC!

Similarly, your Model shouldn't care about the Window size of the application, that's the job of the View.
There is no one like you in the universe.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
January 14 2014 03:23 GMT
#8506
Ah, I see what you're saying! Thanks for pointing that out, I'll definitely try to fix that. Throughout working on the project that was one thing that kept bugging me and now I see why.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
sob3k
Profile Blog Joined August 2009
United States7572 Posts
January 14 2014 03:39 GMT
#8507
On January 14 2014 11:41 phar wrote:
Show nested quote +
On January 14 2014 10:30 sob3k wrote:
If I want to add H1-H6 headers to a previously made page for SEO purposes, if there any way for me to remove all formatting from them? I just want to stick them on as SEO markers and not have them effect the site visibly at all. Right now they break all kinds of stuff. I tried some resets but none of them reduce the headings to just tags.

I'm gonna avoid commenting on whether or not you should be doing that for SEO purposes, but have you looked at the page's css at all? That should be controlling the way stuff looks, not so much your html.


yes, the issue is that H tags come with some sort of (hidden) default styling
In Hungry Hungry Hippos there are no such constraints—one can constantly attempt to collect marbles with one’s hippo, limited only by one’s hippo-levering capabilities.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
January 14 2014 08:02 GMT
#8508
On January 14 2014 12:39 sob3k wrote:
Show nested quote +
On January 14 2014 11:41 phar wrote:
On January 14 2014 10:30 sob3k wrote:
If I want to add H1-H6 headers to a previously made page for SEO purposes, if there any way for me to remove all formatting from them? I just want to stick them on as SEO markers and not have them effect the site visibly at all. Right now they break all kinds of stuff. I tried some resets but none of them reduce the headings to just tags.

I'm gonna avoid commenting on whether or not you should be doing that for SEO purposes, but have you looked at the page's css at all? That should be controlling the way stuff looks, not so much your html.


yes, the issue is that H tags come with some sort of (hidden) default styling

Which is why you always use reset css nowadays, either writing your own, or getting a premade one, such as this:
http://www.cssreset.com/
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
January 14 2014 09:59 GMT
#8509
Hey guys. Long time since I've posted here I think.

I'm having trouble connecting the front end to the back end of a .net website. I'm not sure how you do it. I guess if I were doing PHP I would first connect to the db then have some in line <?php tags to get the data from the db and echo out what I need from the db.

How does .net handle this?
What if I wanted a table of data?

c# code:

public JsonResult GetUserNameAsJson()
{
var userContext = new UsersContext();
User user = userContext.GetUser(User.Identity.Name);

return Json(user, JsonRequestBehavior.AllowGet);
}


This might be what the function above spits out if I call it directly.
{"UserID":1,"UserName":"booger","Password":"5f4dcc3b5aa765d61d8327deb882cf99","Email":"booger@gmail.com"}

Now what if I wanted the html file to call the function?
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
Last Edited: 2014-01-14 10:04:23
January 14 2014 10:02 GMT
#8510
On January 14 2014 18:59 obesechicken13 wrote:
Hey guys. Long time since I've posted here I think.

I'm having trouble connecting the front end to the back end of a .net website. I'm not sure how you do it. I guess if I were doing PHP I would first connect to the db then have some in line <?php tags to get the data from the db and echo out what I need from the db.

How does .net handle this?
What if I wanted a table of data?

c# code:

public JsonResult GetUserNameAsJson()
{
var userContext = new UsersContext();
User user = userContext.GetUser(User.Identity.Name);

return Json(user, JsonRequestBehavior.AllowGet);
}


This might be what the function above spits out if I call it directly.
{"UserID":1,"UserName":"booger","Password":"5f4dcc3b5aa765d61d8327deb882cf99","Email":"booger@gmail.com"}

Now what if I wanted the html file to call the function?

HTML can't call functions. What you have to use in a case like this is javascript, for example, the Jquery .ajax() call.

You can write inline code in asp.net using <% %> syntax, but you're really not supposed to, it makes for hard to maintain code. It also depends on whether or not you're using webforms or MVC, if you want to go this route.
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
January 14 2014 10:10 GMT
#8511
you could use WebApi
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2014-01-14 10:18:11
January 14 2014 10:17 GMT
#8512
I'm using MVC and I've tried lots of javascript and in particular ajax calls. But I'm not sure what to do after I have the javascript to test if its actually working.

For instance I might have this code:
$(function () {
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
url: 'UserController.cs/GetUserNameAsJson',
data: '{ FirstName: "Dave", LastName: "Ward" }'
});
});

Great. Now what does it do?

By itself this returns nothing visible on the client side.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
Last Edited: 2014-01-14 10:49:39
January 14 2014 10:48 GMT
#8513
On January 14 2014 19:17 obesechicken13 wrote:
I'm using MVC and I've tried lots of javascript and in particular ajax calls. But I'm not sure what to do after I have the javascript to test if its actually working.

For instance I might have this code:
$(function () {
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
url: 'UserController.cs/GetUserNameAsJson',
data: '{ FirstName: "Dave", LastName: "Ward" }'
});
});

Great. Now what does it do?

By itself this returns nothing visible on the client side.

Well, you need to output it somewhere, this is covered in many tutorials, the most common way to test it is to output the result in an alert() or console.log() call. Add ".done(function(data) {alert(data); })" to the .ajax() call.

One thing of note, your url is probably incorrect. UserController.cs makes no sense to your server, it should probably be /User/GetUserNameAsJson.
tofucake
Profile Blog Joined October 2009
Hyrule19228 Posts
January 14 2014 13:04 GMT
#8514
little note: .done() is deprecated in 1.8+, use .success() instead
Liquipediaasante sana squash banana
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
January 14 2014 16:38 GMT
#8515
I went to bed. Changed code to
$(function () {
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
url: '/User/GetUserNameAsJson',
data: '{ FirstName: "Dave", LastName: "Ward" }'
}).success(function (data) { alert(data); });
});


I'm getting an error now. Ok I'll just ask one of my friends and copy him.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
Mavvie
Profile Blog Joined May 2012
Canada923 Posts
Last Edited: 2014-01-14 21:25:57
January 14 2014 21:24 GMT
#8516
I've never used a .NET stack, but in this code:

public JsonResult GetUserNameAsJson()
{
var userContext = new UsersContext();
User user = userContext.GetUser(User.Identity.Name);

return Json(user, JsonRequestBehavior.AllowGet);
}


AllowGet...does that deny POST? Because you're doing a POST. Try changing it to a GET would be my guess.

Edit: nvm, googled it and it doesn't deny other types. sorry.
Getting back into sc2 O_o
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
January 14 2014 22:34 GMT
#8517
I remember having studied some term that represents an empty while loop but I can't remember how it was used exactly and why. I suppose it was like this:


while (mailbox.isEmpty()) {} // <--- I am talking about such loop

// now the mailbox isn't empty, so execute something?
mailbox.processLetters();


Does anyone remember something like this? If yes, what is a possible application? Threading?
Shikada
Profile Joined May 2012
Serbia976 Posts
January 14 2014 22:49 GMT
#8518
On January 15 2014 07:34 darkness wrote:
I remember having studied some term that represents an empty while loop but I can't remember how it was used exactly and why. I suppose it was like this:


while (mailbox.isEmpty()) {} // <--- I am talking about such loop

// now the mailbox isn't empty, so execute something?
mailbox.processLetters();


Does anyone remember something like this? If yes, what is a possible application? Threading?


Like this it only serves to waste computer resources. You drive a thread to 100% use for no reason.

If it was:

while(DoSomething) {}


It would do something in that method, and the method would return false to indicate that the work is complete and the loop should stop. That at least make sense, but it's still bad programming (maybe for something really low level). What you would do instead is some well established pattern of asynchronous concurrency, like event driven programming.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2014-01-14 23:36:35
January 14 2014 23:34 GMT
#8519
On January 15 2014 07:49 Shikada wrote:
Show nested quote +
On January 15 2014 07:34 darkness wrote:
I remember having studied some term that represents an empty while loop but I can't remember how it was used exactly and why. I suppose it was like this:


while (mailbox.isEmpty()) {} // <--- I am talking about such loop

// now the mailbox isn't empty, so execute something?
mailbox.processLetters();


Does anyone remember something like this? If yes, what is a possible application? Threading?


Like this it only serves to waste computer resources. You drive a thread to 100% use for no reason.

If it was:

while(DoSomething) {}


It would do something in that method, and the method would return false to indicate that the work is complete and the loop should stop. That at least make sense, but it's still bad programming (maybe for something really low level). What you would do instead is some well established pattern of asynchronous concurrency, like event driven programming.


This is is actually kind of how asynchronous/event programming works.

So for the example darkness gave.

while (mailbox.isEmpty()) {} // <--- I am talking about such loop

// now the mailbox isn't empty, so execute something?
mailbox.processLetters();


The while loop would be running on another thread, also you would add a sleep to it because latency doesn't matter in this case and no need to burn the cpu. Once the while loop breaks, it would call processLetters and then restart the loop again.

Even though its hidden in some frameworks, most basic asynchronous programming has polling that's exactly like this.

The example you gave though wouldn't use a while loop. Instead you would return a "promise" to indicate that the asynchronous process has finished.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Zocat
Profile Joined April 2010
Germany2229 Posts
Last Edited: 2014-01-14 23:44:58
January 14 2014 23:43 GMT
#8520
It's called busy spin / spin lock afaik.
Overall you should avoid using it, since it just burns the CPU.

I think one thing were you can use it was when you only have to wait for very very short amount of times where implementing events would introduce a larger overhead. (No idea if that's true though, never used it)
Prev 1 424 425 426 427 428 1032 Next
Please log in or register to reply.
Live Events Refresh
Epic.LAN
13:00
Epic.LAN 48 Playoff Stage
epiclan33
Liquipedia
WardiTV Invitational
12:00
Summer Cup 2026 - Group A
WardiTV826
LiquipediaDiscussion
CranKy Ducklings
10:00
Master Swan Open #105
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko579
BRAT_OK 121
Rex 120
RushiSC 29
StarCraft: Brood War
Calm 8820
Rain 2351
Shuttle 1961
Hyuk 1460
Jaedong 1214
Mini 633
Horang2 478
BeSt 416
Stork 249
Larva 217
[ Show more ]
Rush 209
ZerO 173
ggaemo 132
hero 130
Last 97
Sharp 94
Pusan 93
Hyun 88
JYJ 82
JulyZerg 68
sorry 52
Killer 51
Free 45
Mong 38
soO 33
Movie 28
HiyA 25
ToSsGirL 25
Shine 24
Aegong 23
Hm[arnc] 16
yabsab 16
Barracks 15
NaDa 15
Yoon 14
Noble 11
ajuk12(nOOB) 9
IntoTheRainbow 8
Rock 8
Icarus 7
Purpose 6
Dota 2
Gorgc6197
XcaliburYe223
League of Legends
Doublelift3147
KnowMe8
Counter-Strike
byalli1738
allub582
kRYSTAL_1
Heroes of the Storm
Khaldor165
Trikslyr24
Other Games
gofns25350
singsing2046
B2W.Neo856
DeMusliM223
RotterdaM207
Hui .159
XaKoH 107
ZerO(Twitch)11
BlysK6
Organizations
Other Games
gamesdonequick2218
BasetradeTV169
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• musti20045 17
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Pr0nogo 5
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 1042
League of Legends
• Jankos2323
Upcoming Events
IPSL
2h 2m
Dragon vs Hawk
RSL Revival
19h 2m
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
20h 2m
OSC
23h 2m
IPSL
1d 2h
Bonyth vs Ret
WardiTV Weekly
1d 21h
Monday Night Weeklies
2 days
OSC
2 days
PiGosaur Cup
3 days
The PondCast
3 days
[ Show More ]
Replay Cast
4 days
CrankTV Team League
4 days
Replay Cast
5 days
CrankTV Team League
5 days
Korean StarCraft League
6 days
RSL Revival
6 days
Liquipedia Results

Completed

Escore Tournament S3: W3
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
YSL S3
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer 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 © 2026 TLnet. All Rights Reserved.