• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 15:28
CET 21:28
KST 05:28
  • 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
ByuL: The Forgotten Master of ZvT28Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
Weekly Cups (Feb 16-22): MaxPax doubles0Weekly Cups (Feb 9-15): herO doubles up2ACS replaced by "ASL Season Open" - Starts 21/0258LiuLi Cup: 2025 Grand Finals (Feb 10-16)46Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2
StarCraft 2
General
Terran AddOns placement How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Nexon's StarCraft game could be FPS, led by UMS maker ByuL: The Forgotten Master of ZvT Oliveira Would Have Returned If EWC Continued
Tourneys
PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) SEL Doubles (SC Evo Bimonthly) WardiTV Team League Season 10 RSL Season 4 announced for March-April The Dave Testa Open #11
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
Mutation # 514 Ulnar New Year The PondCast: SC2 News & Results Mutation # 513 Attrition Warfare Mutation # 512 Overclocked
Brood War
General
TvZ is the most complete match up BGH Auto Balance -> http://bghmmr.eu/ Soma Explains: JD's Unrelenting Aggro vs FlaSh ACS replaced by "ASL Season Open" - Starts 21/02 BW General Discussion
Tourneys
[LIVE] [S:21] ASL Season Open Day 1 ASL Season 21 Qualifiers March 7-8 [Megathread] Daily Proleagues Small VOD Thread 2.0
Strategy
Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Simple Questions, Simple Answers Zealot bombing is no longer popular?
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Path of Exile Beyond All Reason New broswer game : STG-World
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine UK Politics Mega-thread YouTube Thread Mexico's Drug War
Fan Clubs
The IdrA Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
YOUTUBE VIDEO
XenOsky
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Inside the Communication of …
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2013 users

The Big Programming Thread - Page 689

Forum Index > General Forum
Post a Reply
Prev 1 687 688 689 690 691 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.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-12-06 17:11:22
December 06 2015 17:10 GMT
#13761
But in that case, any time I do Animal.talk(); won't it just say "Animal" regardless of if it is a cat or a dog?

Or does it not work that way? do the subclasses get priority?
ShAsTa
Profile Joined November 2002
Belgium2841 Posts
Last Edited: 2015-12-06 17:16:26
December 06 2015 17:15 GMT
#13762
No, it will use the method of the actual, runtime type regardless of the statically defined type.
If we hit that bull's eye, the rest of the dominoes will fall like a house of cards. Checkmate.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
December 06 2015 17:16 GMT
#13763
hmm okay.

so is this how I am supposed to do it if I want to print the fields that are both in the subclass and in the superclass:


public String getInfo(){
return this.getArtist()+this.getSongs()+super.getTitle()+super.getCopies();
}
Acrofales
Profile Joined August 2010
Spain18224 Posts
Last Edited: 2015-12-06 17:23:34
December 06 2015 17:17 GMT
#13764
On December 07 2015 02:10 travis wrote:
But in that case, any time I do Animal.talk(); won't it just say "Animal" regardless of if it is a cat or a dog?

Or does it not work that way? do the subclasses get priority?


That's how polymorphism works. Just use the example above, and try the following:


Animal heffalump = new Animal();
Animal felix = new Cat();
Animal scooby = new Dog();

heffalump.talk();
felix.talk();
scooby.talk();


And watch the magic happen.

And connecting this back to our discussion on setters in the constructor, this is the only reason I can really think of why calling setters from the constructor can be a problem. If you override the setters in your subclasses, then you run a (very real and hard to debug) risk of breaking the superclass' constructor. So in general, my answer earlier went a bit overboard on the use of setters (and getters): the constructor is probably the only place where you shouldn't do that... although there is a caveat in that if the way you are overriding getters and setters in the subclass breaks superclass functionality, you are probably messing stuff up in any case, whether that is in the constructor or otherwise and you should rethink your design.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-12-06 17:18:35
December 06 2015 17:18 GMT
#13765
Should check up on the Wikipedia article on Polymorphism https://en.wikipedia.org/wiki/Polymorphism_(computer_science) , specifically on Virtual Tables https://en.wikipedia.org/wiki/Virtual_method_table

---

You should be doing that in the subclass where you have access to the subclass and superclass methods.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-12-06 17:36:20
December 06 2015 17:25 GMT
#13766
Geeze thanks guys. I was taught about polymorphism but never actually used it, so I kinda never really understood it

but this is just like the coolest thing in the world lol

I am really happy with my decision to go into computer science lol
this is so much more interesting than other career paths I could have gone down
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 06 2015 17:41 GMT
#13767
On December 07 2015 02:17 Acrofales wrote:
And connecting this back to our discussion on setters in the constructor, this is the only reason I can really think of why calling setters from the constructor can be a problem. If you override the setters in your subclasses, then you run a (very real and hard to debug) risk of breaking the superclass' constructor. So in general, my answer earlier went a bit overboard on the use of setters (and getters): the constructor is probably the only place where you shouldn't do that... although there is a caveat in that if the way you are overriding getters and setters in the subclass breaks superclass functionality, you are probably messing stuff up in any case, whether that is in the constructor or otherwise and you should rethink your design.

Generally, calling virtual methods from inside a constructor is a potential risk and not recommended. Some languages can deal with it, some can't, at least not always (an overriden method might access a field of the subclass while the subclass hasn't been constructed/initialized yet). And if they can deal with it, it usually is still prone to errors or not working as you'd expect. And if I remember correctly, methods in Java are virtual by default, so you have to be careful with just about any method call in a constructor.
If you have a good reason to disagree with the above, please tell me. Thank you.
Acrofales
Profile Joined August 2010
Spain18224 Posts
December 06 2015 17:44 GMT
#13768
On December 07 2015 02:16 travis wrote:
hmm okay.

so is this how I am supposed to do it if I want to print the fields that are both in the subclass and in the superclass:


public String getInfo(){
return this.getArtist()+this.getSongs()+super.getTitle()+super.getCopies();
}


Try to avoid calling super where necessary. Imagine the following:

public class Media {

protected String title;

public String getTitle() {
return "Generic media: " + title;
}
}

public class Movie extends Media {

public String getTitle() {
return "Movie: " + title;
}
}


Now, lets say you instantiate a Movie called "Terminator". If you explicitly call super.getTitle(), you will get "Generic media: Terminator" instead of "Movie: Terminato" from just calling getTitle().

A subclass inherits all public and protected methods and fields from its parent, so unless you explicitly want to refer to something that is being done differently in the parent and the child, and you want the parent's way of doing it, don't use super.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 06 2015 17:54 GMT
#13769
On December 07 2015 02:44 Acrofales wrote:
Show nested quote +
On December 07 2015 02:16 travis wrote:
hmm okay.

so is this how I am supposed to do it if I want to print the fields that are both in the subclass and in the superclass:


public String getInfo(){
return this.getArtist()+this.getSongs()+super.getTitle()+super.getCopies();
}


Try to avoid calling super where necessary. Imagine the following:

public class Media {

protected String title;

public String getTitle() {
return "Generic media: " + title;
}
}

public class Movie extends Media {

public String getTitle() {
return "Movie: " + title;
}
}


Now, lets say you instantiate a Movie called "Terminator". If you explicitly call super.getTitle(), you will get "Generic media: Terminator" instead of "Movie: Terminato" from just calling getTitle().

A subclass inherits all public and protected methods and fields from its parent, so unless you explicitly want to refer to something that is being done differently in the parent and the child, and you want the parent's way of doing it, don't use super.

Protected fields aren't such a great idea either. That's just another way of putting the superclass into an invalid state.
Either have the superclass handle all title formatting itself (maybe using the template method pattern if you need to) or handle the title logic in each subclass individually.
If you have a good reason to disagree with the above, please tell me. Thank you.
Acrofales
Profile Joined August 2010
Spain18224 Posts
December 06 2015 17:56 GMT
#13770
On December 07 2015 02:41 spinesheath wrote:
Show nested quote +
On December 07 2015 02:17 Acrofales wrote:
And connecting this back to our discussion on setters in the constructor, this is the only reason I can really think of why calling setters from the constructor can be a problem. If you override the setters in your subclasses, then you run a (very real and hard to debug) risk of breaking the superclass' constructor. So in general, my answer earlier went a bit overboard on the use of setters (and getters): the constructor is probably the only place where you shouldn't do that... although there is a caveat in that if the way you are overriding getters and setters in the subclass breaks superclass functionality, you are probably messing stuff up in any case, whether that is in the constructor or otherwise and you should rethink your design.

Generally, calling virtual methods from inside a constructor is a potential risk and not recommended. Some languages can deal with it, some can't, at least not always (an overriden method might access a field of the subclass while the subclass hasn't been constructed/initialized yet). And if they can deal with it, it usually is still prone to errors or not working as you'd expect. And if I remember correctly, methods in Java are virtual by default, so you have to be careful with just about any method call in a constructor.

Okay. I'm convinced. I convinced myself with the following (silly) code

+ Show Spoiler [breaks with setters in constructor] +


public class Number {
protected int value;

public Number(int value) {
setValue(value);
}

public setValue(int value) {
this.value = value;
}

public getValue() {
return value;
}
}

public class BigNumber extends Number {

private final Number size;

public BigNumber(int value, Number size) {
super(value);
this.size = size;
}

public setValue(int value) throws ValueException{
if(value > size.getValue()) {
this.value = value;
}
else throw new ValueException("not a big number");
}
}

obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
December 07 2015 23:39 GMT
#13771
When you do application level monitoring for a web app, do you do it on a controller level or service level?

The controller is where I map all the rest endpoints.
The service is where the logic gets done and the stuff is put into a db.


I kinda want to know what the response times of the controller methods are because that's what users use. It's possible for multiple controller methods to call one service and I want the granularity to see which one was called. But at the same time it's possible for 2 service methods to be mapped to 1 controller. :/
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.
phar
Profile Joined August 2011
United States1080 Posts
December 08 2015 01:21 GMT
#13772
Both. Having separate monitoring for your individual service calls is nice, because it can let you know if one of your dependencies is having issues.

Actually I'd advocate for more monitoring as well - get some client side stuff in your js (e.g. google analytics or something like that).
Who after all is today speaking about the destruction of the Armenians?
Manit0u
Profile Blog Joined August 2004
Poland17674 Posts
Last Edited: 2015-12-09 06:11:45
December 08 2015 02:57 GMT
#13773
If you want to monitor your web app, you can also think about adopting an event-driven system where your controllers simply dispatch events and you have listeners set up. This way you can monitor whatever you want, whenever you want. Personally, I think that Sylius did a great job with that. For example they've created a generic ResourceController which all the others extend. It has all the basic CRUD operations and automatically ties the events to them (doc). But they went further than that and basically made the entire system operate on events, all of the cart operations, mailing etc. are driven by them.

It's also nice because you can then move your logic away from controllers - they only do basic stuff and dispatch events and all the heavy lifting is done by services triggered by event listeners. This gives you nice flexibility since you no longer call the services directly. With this approach you also get nice separation between the MVC layers.
Time is precious. Waste it wisely.
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
December 09 2015 06:01 GMT
#13774
Ok!
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.
Manit0u
Profile Blog Joined August 2004
Poland17674 Posts
Last Edited: 2015-12-09 14:54:34
December 09 2015 14:52 GMT
#13775
I'm in a bit of a pickle here and hope anyone could help me.

I'm trying to parse a csv file. The problem is that some fields in it are really big ints like 1870000000011550. When such line is read and cast to int it obviously gets truncated (and I can't have that). One possible solution here would be changing all such fields to be explicit strings "1870000000011550". When I try to change their type from number to string in office it changes them to stuff like 1,87000000000570E+015.

Does anyone know of a good way to use some editor (vim, notepad++ whatever) to pre/append the quotes to all numbers in a file that's over 20k lines long?
Time is precious. Waste it wisely.
Ropid
Profile Joined March 2009
Germany3557 Posts
December 09 2015 15:03 GMT
#13776
Can't you use a regex rule and "sed" or your text editor's search-and-replace?
"My goal is to replace my soul with coffee and become immortal."
Manit0u
Profile Blog Joined August 2004
Poland17674 Posts
Last Edited: 2015-12-09 15:25:23
December 09 2015 15:12 GMT
#13777
Notepad++ saved me here.

Search: ([0-9]{16})
Replace: "\1"

Phew!

Edit:

Scratch that. Both office and file reading functions in PHP still treat those fields as numbers instead of text
Time is precious. Waste it wisely.
tofucake
Profile Blog Joined October 2009
Hyrule19193 Posts
December 09 2015 15:42 GMT
#13778
I know you can get around this in Excel by prepending a single quote to the data. That forces Excel to read the field as a string. In PHP you could probably just drop the quote and type cast it.
Liquipediaasante sana squash banana
Ropid
Profile Joined March 2009
Germany3557 Posts
Last Edited: 2015-12-09 15:46:45
December 09 2015 15:46 GMT
#13779
EDIT: too slow

I searched around with regards to Office. When working inside Excel, the trick you'd use to make it treat a bunch of digits as a string instead of a number is putting a ' in front of it. Instead of 123 you'd type '123 into the cell. Perhaps that trick also works when you make Excel import CSV data?

I also tried this '123 with LibreOffice and it's the same behavior there. If this is some sort of standard, perhaps the CSV reading thingy you use in your PHP code also behaves similarly?
"My goal is to replace my soul with coffee and become immortal."
BByte
Profile Joined August 2011
Finland49 Posts
Last Edited: 2015-12-09 16:02:17
December 09 2015 16:01 GMT
#13780
You can also sometimes trick Excel by changing the file extension to txt -- assuming it's currently csv. Alternatively "Paste Special" or similar functionality may work. Excel should also handle large integers correctly.

What are you using to read the file in PHP? Both fgetcsv and str_getcsv should return an array of strings whether you have quotes around numbers or not.
Prev 1 687 688 689 690 691 1032 Next
Please log in or register to reply.
Live Events Refresh
AI Arena Tournament
20:00
RO8
Laughngamez YouTube
DaveTesta Events
18:15
The Dave Testa Open #11
davetesta32
Liquipedia
PSISTORM Gaming Misc
16:55
FSL s10 TeamLeague: ASH vs PTB
Freeedom34
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SteadfastSC 175
ProTech146
JuggernautJason101
gerald23 38
PattyMac 6
StarCraft: Brood War
Britney 24327
Sea 2172
JYJ 27
Dota 2
LuMiX1
Super Smash Bros
hungrybox726
Heroes of the Storm
Khaldor311
Other Games
gofns23944
tarik_tv13999
summit1g3910
Grubby2808
Beastyqt709
B2W.Neo600
crisheroes225
Liquid`Hasu160
ToD158
mouzStarbuck154
KnowMe126
Mew2King47
ZombieGrub32
Organizations
Other Games
gamesdonequick754
Counter-Strike
PGL231
Other Games
WardiTV192
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• printf 74
• Response 6
• IndyKCrew
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• Pr0nogo 4
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Jankos2869
• Shiphtur359
Other Games
• imaqtpie880
Upcoming Events
Replay Cast
3h 32m
PiG Sty Festival
12h 32m
Clem vs Serral
Maru vs ShoWTimE
Sparkling Tuna Cup
13h 32m
uThermal 2v2 Circuit
18h 32m
Replay Cast
1d 12h
Wardi Open
1d 15h
Monday Night Weeklies
1d 20h
Replay Cast
2 days
Replay Cast
3 days
Replay Cast
4 days
[ Show More ]
The PondCast
4 days
KCM Race Survival
4 days
Replay Cast
5 days
Replay Cast
6 days
CranKy Ducklings
6 days
Liquipedia Results

Completed

Proleague 2026-02-26
LiuLi Cup: 2025 Grand Finals
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Acropolis #4 - TS5
Jeongseon Sooper Cup
Spring Cup 2026
[S:21] ASL SEASON OPEN 2nd Round
[S:21] ASL SEASON OPEN 2nd Round Qualifier
WardiTV Winter 2026
PiG Sty Festival 7.0
Nations Cup 2026
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025

Upcoming

ASL Season 21: Qualifier #1
ASL Season 21: Qualifier #2
ASL Season 21
Acropolis #4 - TS6
Acropolis #4
IPSL Spring 2026
CSLAN 4
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
NationLESS Cup
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
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.