• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:15
CEST 22:15
KST 05:15
  • 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
Team Liquid Map Contest #22 - The Finalists11[ASL21] Ro16 Preview Pt1: Fresh Flow9[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy21
Community News
2026 GSL Season 1 Qualifiers9Maestros of the Game 2 announced32026 GSL Tour plans announced8Weekly Cups (April 6-12): herO doubles, "Villains" prevail0MaNa leaves Team Liquid19
StarCraft 2
General
My $23k In USDT Were Recovered By SurgeHack Recove Team Liquid Map Contest #22 - The Finalists Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid 2026 GSL Tour plans announced
Tourneys
2026 GSL Season 1 Qualifiers Sparkling Tuna Cup - Weekly Open Tournament Master Swan Open (Global Bronze-Master 2) SEL Doubles (SC Evo Bimonthly) $5,000 WardiTV TLMC tournament - Presented by Monster Energy
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 521 Memorable Boss The PondCast: SC2 News & Results Mutation # 520 Moving Fees Mutation # 519 Inner Power
Brood War
General
Data needed BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion ASL21 General Discussion A cwal.gg Extension - Easily keep track of anyone
Tourneys
[ASL21] Ro16 Group B [Megathread] Daily Proleagues [ASL21] Ro16 Group A [ASL21] Ro24 Group F
Strategy
What's the deal with APM & what's its true value Any training maps people recommend? Fighting Spirit mining rates Muta micro map competition
Other Games
General Games
General RTS Discussion Thread Battle Aces/David Kim RTS Megathread Nintendo Switch Thread Stormgate/Frost Giant Megathread Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
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 Five o'clock TL Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Canadian Politics Mega-thread European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Reappraising The Situation T…
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2014 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
Spain18262 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
Spain18262 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
Spain18262 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
Poland17723 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
Poland17723 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
Poland17723 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
Hyrule19203 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
Next event in 3h 45m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
EmSc Tv 18
StarCraft: Brood War
Britney 20791
Soma 320
Rush 171
firebathero 145
Soulkey 128
ggaemo 74
Hyun 31
Free 28
Dota 2
canceldota49
LuMiX1
League of Legends
goblin57
Counter-Strike
fl0m7708
Heroes of the Storm
Liquid`Hasu363
Other Games
summit1g5857
Grubby2693
FrodaN800
Beastyqt609
B2W.Neo309
KnowMe192
C9.Mang0143
ArmadaUGS106
ZombieGrub54
Trikslyr49
QueenE42
Mew2King23
KawaiiRice1
Organizations
Counter-Strike
PGL77
StarCraft 2
angryscii 49
EmSc Tv 18
EmSc2Tv 18
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 23 non-featured ]
StarCraft 2
• StrangeGG 80
• davetesta33
• Shameless 32
• IndyKCrew
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• blackmanpl 44
• HerbMon 22
• 80smullet 19
• FirePhoenix10
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2320
League of Legends
• TFBlade1349
• Doublelift855
Other Games
• imaqtpie901
• Scarra523
• Shiphtur89
Upcoming Events
Replay Cast
3h 45m
The PondCast
13h 45m
WardiTV Map Contest Tou…
14h 45m
CranKy Ducklings
1d 3h
Escore
1d 13h
WardiTV Map Contest Tou…
1d 14h
OSC
1d 18h
Korean StarCraft League
2 days
CranKy Ducklings
2 days
WardiTV Map Contest Tou…
2 days
[ Show More ]
IPSL
2 days
WolFix vs nOmaD
dxtr13 vs Razz
BSL
2 days
Sparkling Tuna Cup
3 days
WardiTV Map Contest Tou…
3 days
Ladder Legends
3 days
BSL
3 days
IPSL
3 days
JDConan vs TBD
Aegong vs rasowy
Replay Cast
4 days
Replay Cast
4 days
Wardi Open
4 days
Afreeca Starleague
4 days
Bisu vs Ample
Jaedong vs Flash
Monday Night Weeklies
4 days
RSL Revival
5 days
Afreeca Starleague
5 days
Barracks vs Leta
Royal vs Light
WardiTV Map Contest Tou…
5 days
RSL Revival
6 days
Liquipedia Results

Completed

Proleague 2026-04-14
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
StarCraft2 Community Team League 2026 Spring
Nations Cup 2026
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
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

KCM Race Survival 2026 Season 2
Escore Tournament S2: W3
Escore Tournament S2: W4
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
RSL Revival: Season 5
2026 GSL S1
WardiTV TLMC #16
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 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.