• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 10:59
CEST 16:59
KST 23:59
  • 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 1 - Final Week6[ASL19] Finals Recap: Standing Tall12HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Weekly Cups (July 7-13): Classic continues to roll2Team TLMC #5 - Submission extension1Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced7Weekly Cups (June 30 - July 6): Classic Doubles7
StarCraft 2
General
RSL Revival patreon money discussion thread Weekly Cups (July 7-13): Classic continues to roll Esports World Cup 2025 - Final Player Roster TL Team Map Contest #5: Presented by Monster Energy Team TLMC #5 - Submission extension
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event RSL: Revival, a new crowdfunded tournament series $5,100+ SEL Season 2 Championship (SC: Evo) WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
External Content
Mutation # 482 Wheel of Misfortune Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome
Brood War
General
Flash Announces Hiatus From ASL BW General Discussion A cwal.gg Extension - Easily keep track of anyone [Guide] MyStarcraft [ASL19] Finals Recap: Standing Tall
Tourneys
CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China [Megathread] Daily Proleagues 2025 ACS Season 2 Qualifier
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile CCLP - Command & Conquer League Project The PlayStation 5
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 HOW TO HIRE A HACKER TO RECOVER STOLEN BITCOIN. Russo-Ukrainian War Thread Summer Games Done Quick 2025! Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 607 users

The Big Programming Thread - Page 796

Forum Index > General Forum
Post a Reply
Prev 1 794 795 796 797 798 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.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 09 2016 21:13 GMT
#15901
oh yeah I didn't even notice it actually does have the object as the return type
ok so bounded type parameter, i'll look at that up
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
November 09 2016 21:20 GMT
#15902
A singleton is a glorified static variable. Static variables are usually bad. Sometimes a singleton is a static constant. That's better, but probably still a pointless use of a pattern.

Don't use singletons just because you only need a single instance of that class. You can consider using them if it is absolutely critical that there never is more than one instance of that class. And even then there might be better alternatives. Singleton is taught way too carelessly and as a result many people think it's a good pattern when it really is not (most of the time). There probably also is a historic reason to the prominence of the pattern, because it allowed people who came from C to use static variables in the then new C++ while still pretending that they have successfully adopted OPP principles.

The pattern has very real drawbacks (threading issues, hard to get away from if needed) that might not be apparent at the moment but often come back to haunt you.
If you have a good reason to disagree with the above, please tell me. Thank you.
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2016-11-09 21:54:12
November 09 2016 21:51 GMT
#15903
There are a rare few good uses for the singleton pattern but none of them make much sense for regular software developement. I recently started a course on Operating System Programming and using singletons there, for example for driver controllers, etc, can make a lot of sense. When you are working with memory mapped external devices you dont want two instances of your controller messing each other up.

There is no build-in support for singletons in the java language. You usually use Singletons in java by either defining a "public static final" member variable in some kind of class or by using a "public static" method which will (lazy) initialize a "private static final" member variable and return it.
Example:
public class BigBadController {

private static BigBadController instance;

public static BigBadController getInstance() {
if (instance == null) {
instance = new BigBadController();
}
return instance;
}

private BigBadController() {
// do stuff
}

}

or if you have a multithreaded application:
public class BigBadController {

private static BigBadController instance;
private static final ReentrantLock lock = new ReentrantLock();

public static BigBadController getInstance() {
try {
lock.lock();
if (instance == null) {
instance = new BigBadController();
}
} finally {
lock.unlock();
}
return instance;
}

private BigBadController() {
// do stuff
}

}
AKnopf
Profile Blog Joined March 2011
Germany259 Posts
November 09 2016 23:09 GMT
#15904
Or you use java enterprise edition and inject a singleton instance. This way you can also implement against an interface instead of the concrete class
The world - its a funny place
Manit0u
Profile Blog Joined August 2004
Poland17248 Posts
November 10 2016 03:52 GMT
#15905
[image loading]
Time is precious. Waste it wisely.
Neshapotamus
Profile Blog Joined May 2006
United States163 Posts
November 10 2016 04:30 GMT
#15906
On November 10 2016 12:52 Manit0u wrote:
[image loading]


Dependency Injection alone is great. I use it for unit testing and such.

However, as soon as you introduce dependency injection, you will almost certainly see it with coupled with "inversion of control".

To implement inversion of control, you will start using a container.

Containers solve dependency injection but introduce object lifetime management problems.

In a typed language, you will trade compile time errors for runtime errors. Why bother using a typed language?

You API design is going to down the shitter.

Eventually, your code it going to be unmanageable because your API is so fucked.
ex: A -> B -> C -> D .... -> Z
People stop caring about API design because ill let my container figure out how to resolve dependencies instead of making the api better.

I don't have a solution to this, but I have seen this happen way too many times. It makes we wonder if dependency injection is the answer. Ultimately, dependency injection is just a glorified term for passing a parameter to a function.

I think functional programming is the answer as this is what functional programming solves inherently in the language.


phar
Profile Joined August 2011
United States1080 Posts
November 10 2016 07:00 GMT
#15907
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html
Who after all is today speaking about the destruction of the Armenians?
Manit0u
Profile Blog Joined August 2004
Poland17248 Posts
November 10 2016 07:07 GMT
#15908
On November 10 2016 16:00 phar wrote:
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html


This reminds me of the good old AbstractSingletonProxyFactoryBean


Convenient proxy factory bean superclass for proxy factory beans that create only singletons.


Taken from "Everything wrong with Java in a single class."
Time is precious. Waste it wisely.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
November 10 2016 07:32 GMT
#15909
On November 10 2016 16:07 Manit0u wrote:
Show nested quote +
On November 10 2016 16:00 phar wrote:
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html


This reminds me of the good old AbstractSingletonProxyFactoryBean

Show nested quote +

Convenient proxy factory bean superclass for proxy factory beans that create only singletons.


Taken from "Everything wrong with Java in a single class."

Is this shit for real or did Spring guys create this shit just for fun and games and shit
"windows bash is a steaming heap of shit" tofucake
ZigguratOfUr
Profile Blog Joined April 2012
Iraq16955 Posts
November 10 2016 07:41 GMT
#15910
On November 10 2016 16:32 Djagulingu wrote:
Show nested quote +
On November 10 2016 16:07 Manit0u wrote:
On November 10 2016 16:00 phar wrote:
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html


This reminds me of the good old AbstractSingletonProxyFactoryBean


Convenient proxy factory bean superclass for proxy factory beans that create only singletons.


Taken from "Everything wrong with Java in a single class."

Is this shit for real or did Spring guys create this shit just for fun and games and shit


Oh it's for real.

I have many more doubts about InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState (from com.sun.java.swing.plaf.nimbus.State).
emperorchampion
Profile Blog Joined December 2008
Canada9496 Posts
November 10 2016 12:44 GMT
#15911
On November 10 2016 16:41 ZigguratOfUr wrote:
Show nested quote +
On November 10 2016 16:32 Djagulingu wrote:
On November 10 2016 16:07 Manit0u wrote:
On November 10 2016 16:00 phar wrote:
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html


This reminds me of the good old AbstractSingletonProxyFactoryBean


Convenient proxy factory bean superclass for proxy factory beans that create only singletons.


Taken from "Everything wrong with Java in a single class."

Is this shit for real or did Spring guys create this shit just for fun and games and shit


Oh it's for real.

I have many more doubts about InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState (from com.sun.java.swing.plaf.nimbus.State).


rofl
TRUEESPORTS || your days as a respected member of team liquid are over
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
November 10 2016 12:49 GMT
#15912
On November 10 2016 16:41 ZigguratOfUr wrote:
Show nested quote +
On November 10 2016 16:32 Djagulingu wrote:
On November 10 2016 16:07 Manit0u wrote:
On November 10 2016 16:00 phar wrote:
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html


This reminds me of the good old AbstractSingletonProxyFactoryBean


Convenient proxy factory bean superclass for proxy factory beans that create only singletons.


Taken from "Everything wrong with Java in a single class."

Is this shit for real or did Spring guys create this shit just for fun and games and shit


Oh it's for real.

I have many more doubts about InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState (from com.sun.java.swing.plaf.nimbus.State).

http://www.javafind.net/gate.jsp?q=/library/36/java6_full_apidocs/com/sun/java/swing/plaf/nimbus/package-tree.html

It's the entire fucking package :D
"windows bash is a steaming heap of shit" tofucake
RoomOfMush
Profile Joined March 2015
1296 Posts
November 10 2016 14:07 GMT
#15913
On November 10 2016 21:49 Djagulingu wrote:
Show nested quote +
On November 10 2016 16:41 ZigguratOfUr wrote:
On November 10 2016 16:32 Djagulingu wrote:
On November 10 2016 16:07 Manit0u wrote:
On November 10 2016 16:00 phar wrote:
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html


This reminds me of the good old AbstractSingletonProxyFactoryBean


Convenient proxy factory bean superclass for proxy factory beans that create only singletons.


Taken from "Everything wrong with Java in a single class."

Is this shit for real or did Spring guys create this shit just for fun and games and shit


Oh it's for real.

I have many more doubts about InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState (from com.sun.java.swing.plaf.nimbus.State).

http://www.javafind.net/gate.jsp?q=/library/36/java6_full_apidocs/com/sun/java/swing/plaf/nimbus/package-tree.html

It's the entire fucking package :D

As far as I know these are auto-generated. No reason to argue about the readability of auto-generated code.
Acrofales
Profile Joined August 2010
Spain17975 Posts
November 10 2016 14:17 GMT
#15914
On November 10 2016 16:41 ZigguratOfUr wrote:
Show nested quote +
On November 10 2016 16:32 Djagulingu wrote:
On November 10 2016 16:07 Manit0u wrote:
On November 10 2016 16:00 phar wrote:
There exists also the concept of using dependency injection to inject... a singleton.

e.g. https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Singleton.html


This reminds me of the good old AbstractSingletonProxyFactoryBean


Convenient proxy factory bean superclass for proxy factory beans that create only singletons.


Taken from "Everything wrong with Java in a single class."

Is this shit for real or did Spring guys create this shit just for fun and games and shit


Oh it's for real.

I have many more doubts about InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState (from com.sun.java.swing.plaf.nimbus.State).


Well, that's just a naming convention gone horribly wrong. I have no idea what the class is supposed to do, but it seems like something you might want to do. The other one... why in the holy hell would anybody create something like that? Just click on it. And then click through to the superclasses and things; there's plenty of goodness there. But before you click, ask yourself one simple question: what does a factory to create singletons do?
Manit0u
Profile Blog Joined August 2004
Poland17248 Posts
November 10 2016 14:36 GMT
#15915
http://evilbydesign.info/

Good read for anyone.
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-11 01:29:43
November 11 2016 01:19 GMT
#15916
it's all coming together..
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-11 01:31:46
November 11 2016 01:25 GMT
#15917
For polymorphism you just need to declare everything as a Tree. The Tree class is your interface or contract of all the methods that your subclasses will implement. Your Tree object knows if its a NonEmptyTree or an EmptyTree and will use the appropriate method due to polymorphism so you don't have to cast or check which class it is.

On November 11 2016 10:19 travis wrote:
For example an insert method

inserting into an empty tree is easy. just return a nonemptytree with the key and value.
inserting into the nonempty tree, I use recursion to check for duplicate key, if i hit a duplicate i replace the value. using compareTo I move left/right down the tree appropriately until.... i hit a leaf. but how the fuck will I know when I hit a leaf? What does polymorphism have to do with any of this?


You're going to have an insert method for the NonEmptyTree class and a different method implementation for the EmptyTree class. Polymorphism as described above will determine which method will be executed. You don't actually know when you hit a leaf. The code does though which is the point of polymorphism.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-11 01:33:48
November 11 2016 01:29 GMT
#15918
OH, so the way I use my methods is by using my "right" and "left" tree members? Since they are either nonemptytree OR emptytree(and they know)?
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-11 01:41:29
November 11 2016 01:37 GMT
#15919
On November 11 2016 10:29 travis wrote:
OH, so the way I use my methods is by using my "right" and "left" tree members? Since they are either nonemptytree OR emptytree?


I'll try to go through an example so it's clear...

Lets say I have a Tree structure like the following where E signifies an EmptyTree and the fourth level is all EmptyTree where I was too lazy to draw the rest of tree:

 root                     8
/ \
6 14
/ \ / \
3 E E 19


So I'm going to insert a new Tree into my structure which has the value 12. My insertion method will be called on the root. This is a NonEmptyTree so we'll be using that insertion method. This method determines if it go to the left or right child based on a simple comparison. 12 is greater than 8 so we'll call the insertion method on the right. Again we've hit a NonEmptyTree so the same thing happens. This time 12 is less than 14 so we'll call the insertion method on the left. Now we've hit an EmptyTree so a different method will be executed. This method is going to replace that node with a NonEmptyTree with the value 12.

Because of polymorphism, the code knows which method to execute and we don't actually know or care.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-11 01:42:48
November 11 2016 01:40 GMT
#15920
Okay I completely understand, that is awesome and makes sense. Thank you.

Suddenly I don't think this design is so annoying.

(it also means this project is way way easier than I thought)
Prev 1 794 795 796 797 798 1031 Next
Please log in or register to reply.
Live Events Refresh
Wardi Open
11:00
#44
WardiTV1675
OGKoka 1058
Rex159
CranKy Ducklings150
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 1058
Rex 159
StarCraft: Brood War
PianO 5140
Rush 1883
Sea 1611
firebathero 1558
EffOrt 1273
JulyZerg 1083
zelot 703
Larva 666
Stork 626
Mong 488
[ Show more ]
Mini 315
Mind 146
Zeus 117
ToSsGirL 104
sorry 93
Pusan 82
Barracks 78
Movie 66
Shinee 56
sSak 47
soO 41
Shine 40
Terrorterran 31
sas.Sziky 31
Rock 16
IntoTheRainbow 9
yabsab 8
Bale 7
SilentControl 7
NaDa 4
Stormgate
NightEnD30
Dota 2
qojqva3439
syndereN585
League of Legends
Dendi1601
febbydoto7
Counter-Strike
flusha479
Super Smash Bros
Mew2King94
Heroes of the Storm
Khaldor219
Other Games
singsing2817
hiko1314
Fuzer 685
crisheroes456
Beastyqt353
Lowko288
oskar233
XcaliburYe233
Hui .224
Liquid`VortiX181
KnowMe103
ArmadaUGS99
QueenE51
Trikslyr1
Organizations
Other Games
gamesdonequick5050
StarCraft: Brood War
Kim Chul Min (afreeca) 7
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• StrangeGG 58
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2532
League of Legends
• Nemesis6008
Upcoming Events
RotterdaM Event
1h 1m
Replay Cast
19h 1m
WardiTV European League
1d 1h
ShoWTimE vs sebesdes
Percival vs NightPhoenix
Shameless vs Nicoract
Krystianer vs Scarlett
ByuN vs uThermal
Harstem vs HeRoMaRinE
PiGosaur Monday
1d 9h
uThermal 2v2 Circuit
2 days
Replay Cast
2 days
The PondCast
2 days
Replay Cast
3 days
Epic.LAN
3 days
CranKy Ducklings
4 days
[ Show More ]
Epic.LAN
4 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs Sziky
Dewalt vs Hawk
Hawk vs QiaoGege
Sziky vs Dewalt
Mihu vs Bonyth
Zhanhun vs QiaoGege
QiaoGege vs Fengzi
Sparkling Tuna Cup
5 days
Online Event
6 days
BSL20 Non-Korean Champi…
6 days
Bonyth vs Zhanhun
Dewalt vs Mihu
Hawk vs Sziky
Sziky vs QiaoGege
Mihu vs Hawk
Zhanhun vs Dewalt
Fengzi vs Bonyth
Liquipedia Results

Completed

2025 ACS Season 2: Qualifier
RSL Revival: Season 1
Murky Cup #2

Ongoing

JPL Season 2
BSL 2v2 Season 3
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
BSL20 Non-Korean Championship
Championship of Russia 2025
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters

Upcoming

CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
BSL Season 21
K-Championship
RSL Revival: Season 2
SEL Season 2 Championship
uThermal 2v2 Main Event
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.