• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:57
CET 09:57
KST 17:57
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband Information Request Regarding Chinese Ladder
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3 Tenacious Turtle Tussle [Alpha Pro Series] Nice vs Cure
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Which season is the best in ASL? [ASL20] Ask the mapmakers — Drop your questions BW General Discussion FlaSh's Valkyrie Copium BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread The Perfect Game Path of Exile Nintendo Switch Thread Should offensive tower rushing be viable in RTS games?
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1165 users

The Big Programming Thread - Page 416

Forum Index > General Forum
Post a Reply
Prev 1 414 415 416 417 418 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
Last Edited: 2013-12-29 22:23:39
December 29 2013 22:19 GMT
#8301
On December 30 2013 06:12 teamamerica wrote:
Anyone have advice on good books/pointers on designing stuff? Writing in object orientated languages, one thing I struggle with is how to design my classes. Things like: should this be static function or instance. Should this be in constructor or passed into function. Should I pass an object and act on a copy, or mutate the object that was passed in.

Also the same question about good references for how to set up relational database schema? e.g. surrogate keys vs natural keys.

One thing I was just working on was...
+ Show Spoiler +

One thing I just worked on had records which had either a "rast" or "patric" type annotation. Each annotation type provided different information i.e. different columns. So for each record I stored "annotation type" as an "enum", and had 2 tables {rast, patric} annotation. My question in this case is twofold:
1) better to have split it into 2 tables or used one larger table (annotation) and nulled out columns as appropriate
2) better to use enum to describe annotation type or a values table (e.g. annotation type column => annotation_types table => "rast" | "patric".
3) and this might be mysql specific. Some of the columns in the annotation table are rather large - 500char+. When to use varchar(500) or "TEXT". Say the column "length" is 500+ characters. I've seen before comments that TEXT and BLOB columns can make table operations that don't even effect these columns really expensive. Should I have stored "length" in a seperate table, and had a lookup table from the main record to it?

The data seemed pretty relational but it feels weird to columns with so much text into a database.


I'm looking through Effective Java which I find pretty interesting, and it kind of covers questions of the second instance, but not really questions of the first instance.


Object Oriented* not Object Orientated

I haven't seen any Java books that are useful.

I've read a ton of books on OO and this is still my favorite

http://www.amazon.com/Object-Design-Roles-Responsibilities-Collaborations/dp/0201379430

Generally avoid using class variables and methods if you can. The less you rely on state the better. Basically your program is a system of collaborating objects that work together to solve a problem. Think of it like an organisation, you have different people specialising in different tasks all working together.

Just incase you missed it, I just gave a guy a refactored tictactoe example with heavy object decomposition and functional decomposition. That's basically all you need to master for the first year, once you have that down you stop wasting time thinking about any of this stuff and the rest comes easy.

https://github.com/DanielShuey/Java-TicTacToe-Example/tree/master/src/tictactoe
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-12-29 22:55:10
December 29 2013 22:54 GMT
#8302
^ the book's title reminds me of CRC (Class-responsibility-collaboration): wikipedia. Is that what it teaches?
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-30 00:37:55
December 30 2013 00:34 GMT
#8303
On December 30 2013 07:54 darkness wrote:
^ the book's title reminds me of CRC (Class-responsibility-collaboration): wikipedia. Is that what it teaches?


Class Responsibility Collaboration is probably an inspiration for Responsibility Driven Design.

CRC cards are really unnecessary though, I've found having brainstorming sessions for design to be a complete wank. 99% of the time you end up just wanting to completely change the design during implementation anyway.

Also the use of CRC cards in extreme programming is usually for writing stories rather than design, extreme programming spends basically 0 time on design, I think that wiki entry is a tad misguided.

Although CRC is probably a really broad and undefined term, where as RDD is a bit more defined and structured. You don't need to spend time brainstorming with RDD either, its just a mindset that you have, at least for me anyways.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
bangsholt
Profile Joined June 2011
Denmark138 Posts
December 30 2013 01:46 GMT
#8304
On December 30 2013 05:30 wozzot wrote:
Programming newbie, making a Rubik's Cube solver, feeling really dumb right now.

I think I can manage to get the cube structure, the transformation subroutine, and solver algorithm going, but I don't know how the hell I should store the cubelet data, the data that tells me that the TL corner of the top face is connected to the TL of the left face and TR of the back face so that I can rotate them together and so on.

Right now, I'm using this and using split to retrieve the face + side/corner pairs:


my cubelets[6][9];
{
cubelets[0][0] = ( ["1 0", "4 2"] );
cubelets[0][1] = "4 1";
cubelets[0][2] = ( ["4 0", "3 2"] );
cubelets[0][3] = "1 1";
cubelets[0][5] = "3 1";
cubelets[0][6] = ( ["1 2", "2 0"] );
cubelets[0][7] = "2 1";
cubelets[0][8] = ( ["2 2", "3 0"] );

cubelets[1][0] = ( ["0 0", "4 2"] );
cubelets[1][1] = "0 3";
cubelets[1][2] = ( ["0 6", "2 0"] );
cubelets[1][3] = "4 5";
cubelets[1][5] = "2 3";
cubelets[1][6] = ( ["4 8", "5 6"] );
cubelets[1][7] = "5 3";
cubelets[1][8] = ( ["2 6", "5 0"] );

cubelets[2][0] = ( ["0 6", "1 2"] );
cubelets[2][1] = "0 7";
cubelets[2][2] = ( ["0 8", "3 0"] );
cubelets[2][3] = "1 5";
cubelets[2][5] = "3 3";
cubelets[2][6] = ( ["1 8", "5 0"] );
cubelets[2][7] = "5 1";
cubelets[2][8] = ( ["3 6", "5 2"] );

...

But I'm pretty sure that this is either non-optimal or I might be approaching this problem completely the wrong way. Am I doing something wrong? Any advice on how to go about doing this?

e: Only on Layer 1 and it's already about 250 lines of code, I'm definitely screwing something up but may as well keep on going


So if I understand it correctly, the first index in your array is an arbitrary side number of the cube and the second index is the squares of the side?

First of all, you could encode the current system of sides and squares into an integer - I'm thinking something like 28 - this would allow you to do a modulus operation to get the side and square. (Example would be: int side = encode / 10, int square = encode % 10)

Then you can save a list of those in a list which holds all the corners of the cube - so basically you would end up with a structure that's like this

List<List<Integer>> corners;

Then you can with ease do a simple for-loop over it and figure out which squares are connected to each other. This of course takes some time to iterate, but for now the important thing is to get it working, then you can start optimizing afterwards
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-12-30 14:56:58
December 30 2013 14:52 GMT
#8305
In PHP things are all set up with lamp/wamp framework and if you want to make a login page you can do it with just a php script and an html form page that passes directly to that php file.

How do you make a login page with c# using the microsoft mvc framework? It's just so confusing.

I'm reading this stuff and they just give you buttons to click. There's so many layers of abstraction that I don't really see what's going on anymore. How does the html form page interact with the back end c# code to authenticate a user?

http://msdn.microsoft.com/en-us/library/879kf95c(v=vs.100).aspx

Can I make a login page that doesn't use membership?
How does the c# aspx file link to the back end mssql database?

Nvm, fuck microsoft, there's a tutorial here:
http://www.daniweb.com/web-development/aspnet/threads/6028/simple-asp.net-login-page-using-vb.net

I can try this.
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
December 30 2013 14:55 GMT
#8306
On December 30 2013 23:52 obesechicken13 wrote:
In PHP things are all set up with lamp/wamp framework and if you want to make a login page you can do it with just a php script and an html form page that passes directly to that php file.

How do you make a login page with c# using the microsoft mvc framework? It's just so confusing.

I'm reading this stuff and they just give you buttons to click. There's so many layers of abstraction that I don't really see what's going on anymore. How does the html form page interact with the back end c# code to authenticate a user?

http://msdn.microsoft.com/en-us/library/879kf95c(v=vs.100).aspx

Can I make a login page that doesn't use membership?

You can make your own login system just fine, it basically works the same as in PHP. A cshtml page with the login form, and a controller to handle the authentication etc. The problem, of course, is to make it secure and good, which is what membership (to some extent) fixes for you. It's quite a complex thing, which is why there are so many layers of abstraction.

(If you want to learn more about the abstractions, try writing your own membership provider, I'm sure there are decent tutorials for it).
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-12-30 15:00:18
December 30 2013 14:58 GMT
#8307
On December 30 2013 23:55 Tobberoth wrote:
Show nested quote +
On December 30 2013 23:52 obesechicken13 wrote:
In PHP things are all set up with lamp/wamp framework and if you want to make a login page you can do it with just a php script and an html form page that passes directly to that php file.

How do you make a login page with c# using the microsoft mvc framework? It's just so confusing.

I'm reading this stuff and they just give you buttons to click. There's so many layers of abstraction that I don't really see what's going on anymore. How does the html form page interact with the back end c# code to authenticate a user?

http://msdn.microsoft.com/en-us/library/879kf95c(v=vs.100).aspx

Can I make a login page that doesn't use membership?

You can make your own login system just fine, it basically works the same as in PHP. A cshtml page with the login form, and a controller to handle the authentication etc. The problem, of course, is to make it secure and good, which is what membership (to some extent) fixes for you. It's quite a complex thing, which is why there are so many layers of abstraction.

(If you want to learn more about the abstractions, try writing your own membership provider, I'm sure there are decent tutorials for it).

Ok that makes sense. Do the membership providers still use your mssql database? If so which tables do they use?

edit: nvm, it looks like you can specify a sql data store, but I still have to figure out how to set that up. Last time I tried to set up memberships I ran into error messages for a day.
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.
Requizen
Profile Blog Joined March 2011
United States33802 Posts
December 30 2013 18:00 GMT
#8308
Anyone have any experience implementing the Twitch API or Javascript commands?
It's your boy Guzma!
Housemd
Profile Joined March 2010
United States1407 Posts
December 30 2013 19:33 GMT
#8309
I'm so lost right now so if someone could help me a little.

So the problem states that I have to print out the numbers from 1 to 100. Simple enough. But then it states that I need to print out their multiples on the same line up until the multiples are less than or equal to 500. For example, on line 99, it should print:

99, 198, 297, 396, 495

I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for
(int i = 1; i <= 100; i++){
System.out.println(i);
}

I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.

Not looking for the answer, just some help on introducing the while loop.

Should I initialize a new variable?
How would I print out the multiples?
Fantasy is a beast
Cyx.
Profile Joined November 2010
Canada806 Posts
Last Edited: 2013-12-30 19:47:30
December 30 2013 19:46 GMT
#8310
On December 31 2013 04:33 Housemd wrote:

I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for
(int i = 1; i <= 100; i++){
System.out.println(i);
}

I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.

Not looking for the answer, just some help on introducing the while loop.

Should I initialize a new variable?
How would I print out the multiples?


Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i.

introduce a new variable x, state (while x <=500), print out x and increment it by i.
Housemd
Profile Joined March 2010
United States1407 Posts
Last Edited: 2013-12-30 20:33:27
December 30 2013 20:28 GMT
#8311
On December 31 2013 04:46 Cyx. wrote:
Show nested quote +
On December 31 2013 04:33 Housemd wrote:

I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for
(int i = 1; i <= 100; i++){
System.out.println(i);
}

I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.

Not looking for the answer, just some help on introducing the while loop.

Should I initialize a new variable?
How would I print out the multiples?


Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i.

Show nested quote +
introduce a new variable x, state (while x <=500), print out x and increment it by i.


Thanks for the help. Just a couple of questions.
int x = 0;
for (int i = 1; i <= 100; i++){
while (x <= 500)
System.out.println(x+=i);

Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?
Fantasy is a beast
WolfintheSheep
Profile Joined June 2011
Canada14127 Posts
December 30 2013 20:51 GMT
#8312
On December 31 2013 05:28 Housemd wrote:
Show nested quote +
On December 31 2013 04:46 Cyx. wrote:
On December 31 2013 04:33 Housemd wrote:

I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for
(int i = 1; i <= 100; i++){
System.out.println(i);
}

I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.

Not looking for the answer, just some help on introducing the while loop.

Should I initialize a new variable?
How would I print out the multiples?


Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i.

introduce a new variable x, state (while x <=500), print out x and increment it by i.


Thanks for the help. Just a couple of questions.
int x = 0;
for (int i = 1; i <= 100; i++){
while (x <= 500)
System.out.println(x+=i);

Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?


Well, just consider what happens when x is 500.

Also, consider what happens when i increments to 2...what is x's value?
Average means I'm better than half of you.
scudst0rm
Profile Joined May 2010
Canada1149 Posts
December 30 2013 21:00 GMT
#8313
On December 31 2013 05:28 Housemd wrote:
Show nested quote +
On December 31 2013 04:46 Cyx. wrote:
On December 31 2013 04:33 Housemd wrote:

I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for
(int i = 1; i <= 100; i++){
System.out.println(i);
}

I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.

Not looking for the answer, just some help on introducing the while loop.

Should I initialize a new variable?
How would I print out the multiples?


Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i.

introduce a new variable x, state (while x <=500), print out x and increment it by i.


Thanks for the help. Just a couple of questions.
int x = 0;
for (int i = 1; i <= 100; i++){
while (x <= 500)
System.out.println(x+=i);

Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?


You're making a pretty big assumption on what x+=i will return and your assumption is wrong.
You're like a one ranger army comin' at me...
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-12-30 22:06:33
December 30 2013 22:05 GMT
#8314
Is lazy initialization always good to use or is there a point of "overuse"? Example code:


private File theFile;
...
public File getFile() {
if (theFile == null) {
theFile = new File(PATH);
}
return theFile;
}
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
December 30 2013 23:06 GMT
#8315
No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.
There is no one like you in the universe.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
December 30 2013 23:38 GMT
#8316
On December 31 2013 08:06 Blisse wrote:
No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.

The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit.

Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so?
killa_robot
Profile Joined May 2010
Canada1884 Posts
Last Edited: 2013-12-31 01:27:44
December 31 2013 01:22 GMT
#8317
On December 31 2013 05:28 Housemd wrote:
Show nested quote +
On December 31 2013 04:46 Cyx. wrote:
On December 31 2013 04:33 Housemd wrote:

I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for
(int i = 1; i <= 100; i++){
System.out.println(i);
}

I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.

Not looking for the answer, just some help on introducing the while loop.

Should I initialize a new variable?
How would I print out the multiples?


Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i.

introduce a new variable x, state (while x <=500), print out x and increment it by i.


Thanks for the help. Just a couple of questions.
int x = 0;
for (int i = 1; i <= 100; i++){
while (x <= 500)
System.out.println(x+=i);

Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?


Nope, it's doing exactly what you're telling it too

Once i = 2 (second time it goes through the outer loop), x is still <= 500, since you set it to 0 outside of the loops. If you want the while loop to run every time i increments, set x=0 within the for loop. You also may want to set x+=i before the println, then just print out x.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-12-31 09:13:55
December 31 2013 09:13 GMT
#8318
On December 31 2013 08:38 Tobberoth wrote:
Show nested quote +
On December 31 2013 08:06 Blisse wrote:
No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.

The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit.

Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so?


I'm not sure how files are handled by OS especially when they're big. But if they take more memory because of their larger size, then I can see a benefit if lazy initialization is used in this case.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-31 09:36:36
December 31 2013 09:32 GMT
#8319
On December 31 2013 08:38 Tobberoth wrote:
Show nested quote +
On December 31 2013 08:06 Blisse wrote:
No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.

The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit.

Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so?


On December 31 2013 08:06 Blisse wrote:
No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.


Applying programming paradigms are extremely important, design patterns are kinda important.

Pre-optimisation and over-engineering however is a bad thing. Some companies use a "computer architect" to come up with an over-engineered UML design before implementing it, that certainly is really stupid.

His example is a classic case of pre-optimisation, not 'applying a design pattern'. It also has nothing to do with a programming paradigm.

You should never ever neglect learning programming paradigms. Mastering programming paradigms will speed up productivity and make sure your code is nice and clean. It basically allows you to write clean code without even having to think about it. People in this thread who need help on cleaning up their code are usually suffering from not knowing the paradigm enough.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2013-12-31 10:08:17
December 31 2013 09:43 GMT
#8320
He's not pre-optimizing anything though. He's asking a question about applying a design pattern. We're saying to be careful of over-using programming paradigms/patterns in cases where they're not necessarily useful. Part of learning a paradigm is to actually learn when they're actually useful, and part of learning paradigms in general is understanding when to use them and when not to, and being wary of overusing them, which is what he originally asked about.

Anyways, it worked, because now he's asking questions about what situations where applying the pattern would be relevant. I think I could have gone into it directly though without the side tangent against overuse. I may have misunderstood the question the first time.



On December 31 2013 18:13 darkness wrote:
Show nested quote +
On December 31 2013 08:38 Tobberoth wrote:
On December 31 2013 08:06 Blisse wrote:
No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.

The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit.

Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so?


I'm not sure how files are handled by OS especially when they're big. But if they take more memory because of their larger size, then I can see a benefit if lazy initialization is used in this case.


Yes, you would see memory (maybe performance as you said) benefits because you're not holding a reference to the large File object.


But most of the time, that would never happen.

When working with files, the standard protocol is keeping the file path, and when you need to do work on it, open the file, do the work, then close the file object.

It is pretty bad practice to keep references to things like files. Mainly because you may forget to deallocate them and you'll have a memory leak, whereas `open, work, close` is very clear.



An example of lazy initialization:

Suppose you had an application that communicated with a server. Typically when the application starts up, you would setup most of your objects, and then begin communication. However, if the server communication is I/O driven, suppose, the user had to type in a password 1234 before anything would happen, then it may be nice to delay setting up until after the password is entered, because you don't necessarily need anything yet. And if the password is not entered or if the user quits, then you wouldn't have wasted time/resources setting up. If the password is entered, then you can now initialize your objects. Of course, this is a poorly engineered example, but hopefully you can see a use and a possible benefit.






On a side note, it is really weird to work coincidentally on 3 separate, dependant projects.

Project C (and in the future, D), are dependent on a common base B, which is dependent on another library, A, all of which I'm writing. Very strange. But it's entertaining being able to engineer all parts of the project and applying crazy design patterns all over the place because I'm bored.

Also, I saw a place in my code where a function had 8 lines of code and I remembered the argument a couple pages back here. Haha.
There is no one like you in the universe.
Prev 1 414 415 416 417 418 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 3m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 202
ProTech112
StarCraft: Brood War
Horang2 2512
actioN 763
Larva 309
Hyun 172
PianO 119
Zeus 102
Pusan 86
Dewaltoss 82
Sharp 51
soO 37
[ Show more ]
NotJumperer 19
Hm[arnc] 6
Dota 2
XaKoH 523
XcaliburYe112
League of Legends
JimRising 537
C9.Mang0283
Counter-Strike
shoxiejesuss389
Super Smash Bros
Westballz18
Other Games
summit1g13090
Happy419
Organizations
Other Games
gamesdonequick724
StarCraft: Brood War
UltimateBattle 80
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH268
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota225
League of Legends
• Lourlo1081
• Stunt604
Counter-Strike
• Carefoot0
Upcoming Events
Wardi Open
3h 3m
StarCraft2.fi
8h 3m
Replay Cast
15h 3m
The PondCast
1d 1h
OSC
1d 7h
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
1d 15h
Korean StarCraft League
2 days
CranKy Ducklings
3 days
SC Evo League
3 days
BSL 21
3 days
Sziky vs OyAji
Gypsy vs eOnzErG
[ Show More ]
OSC
3 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
4 days
OSC
4 days
BSL 21
4 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
5 days
Wardi Open
5 days
StarCraft2.fi
5 days
Replay Cast
5 days
StarCraft2.fi
6 days
PiGosaur Monday
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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...

Disclosure: This page contains affiliate marketing links that support TLnet.

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.