• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 17:14
CET 23:14
KST 07:14
  • 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 Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets0$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)14Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1823
StarCraft 2
General
SC2 All-Star Invitational: Jan 17-18 When will we find out if there are more tournament SC2 Spotted on the EWC 2026 list? Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns
Tourneys
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) $25,000 Streamerzone StarCraft Pro Series announced WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes
Brood War
General
[ASL21] Potential Map Candidates Potential ASL qualifier breakthroughs? A cwal.gg Extension - Easily keep track of anyone BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
Beyond All Reason Nintendo Switch Thread Awesome Games Done Quick 2026! Mechabellum Stormgate/Frost Giant Megathread
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
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Trading/Investing Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1069 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
Spain18180 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
Spain18180 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
Spain18180 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
Poland17596 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
Poland17596 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
Poland17596 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
Hyrule19188 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
BSL: GosuLeague
21:00
QUARTER FINALS
ZZZero.O101
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JuggernautJason150
Nathanias 100
CosmosSc2 16
StarCraft: Brood War
Shuttle 458
UpATreeSC 223
ZZZero.O 101
League of Legends
C9.Mang0171
Counter-Strike
apEX3119
shoxiejesuss2609
Coldzera 685
Foxcn139
minikerr29
Super Smash Bros
Chillindude31
Other Games
Grubby2980
Liquid`RaSZi2549
Gorgc2164
FrodaN945
B2W.Neo631
Beastyqt561
shahzam484
Liquid`Hasu269
ArmadaUGS249
QueenE132
XaKoH 104
ToD100
ViBE57
OptimusSC26
Organizations
Other Games
gamesdonequick3056
StarCraft 2
angryscii 39
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• StrangeGG 31
• musti20045 25
• Kozan
• Migwel
• sooper7s
• AfreecaTV YouTube
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• HerbMon 25
• Pr0nogo 2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV704
• masondota2199
League of Legends
• TFBlade961
Other Games
• imaqtpie2060
• Shiphtur235
Upcoming Events
PiGosaur Cup
2h 46m
WardiTV Invitational
13h 46m
The PondCast
1d 11h
OSC
1d 13h
OSC
2 days
All Star Teams
3 days
INnoVation vs soO
sOs vs Scarlett
uThermal 2v2 Circuit
3 days
All Star Teams
4 days
MMA vs DongRaeGu
Rogue vs Oliveira
Sparkling Tuna Cup
4 days
OSC
4 days
[ Show More ]
Replay Cast
5 days
Wardi Open
5 days
Liquipedia Results

Completed

Proleague 2026-01-12
Big Gabe Cup #3
NA Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
OSC Championship Season 13
Underdog Cup #3
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Nations Cup 2026
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
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.