• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:54
CET 19:54
KST 03:54
  • 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 - 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[ASL20] Finals Preview: Arrival13
Community News
Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge1[TLMC] Fall/Winter 2025 Ladder Map Rotation14Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" [TLMC] Fall/Winter 2025 Ladder Map Rotation Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge Mech is the composition that needs teleportation t RSL Season 3 - RO16 Groups C & D Preview
Tourneys
2025 RSL Offline Finals Dates + Ticket Sales! $5,000+ WardiTV 2025 Championship RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review BW General Discussion
Tourneys
[BSL21] GosuLeague T1 Ro16 - Tue & Thu 22:00 CET [Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET
Strategy
Current Meta How to stay on top of macro? PvZ map balance Simple Questions, Simple Answers
Other Games
General Games
Clair Obscur - Expedition 33 Beyond All Reason Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? Path of Exile
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI About SC2SEA.COM
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1521 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
Spain18124 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
Spain18124 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
Spain18124 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
Poland17440 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
Poland17440 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
Poland17440 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
Hyrule19155 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 2h 6m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 436
UpATreeSC 86
StarCraft: Brood War
Britney 28102
Rain 3142
Calm 2798
GuemChi 567
Dewaltoss 133
Leta 67
scan(afreeca) 30
zelot 27
Movie 19
yabsab 16
Dota 2
qojqva3266
Dendi1015
Counter-Strike
pashabiceps1051
Heroes of the Storm
Liquid`Hasu32
Other Games
FrodaN3814
DeMusliM473
ceh9473
KnowMe166
ArmadaUGS119
C9.Mang073
Trikslyr63
MindelVK9
Organizations
StarCraft 2
angryscii 11
StarCraft: Brood War
lovetv 9
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 21 non-featured ]
StarCraft 2
• Hinosc 29
• Reevou 3
• Dystopia_ 1
• sooper7s
• AfreecaTV YouTube
• Migwel
• LaughNgamezSOOP
• intothetv
• IndyKCrew
• Kozan
StarCraft: Brood War
• FirePhoenix19
• blackmanpl 14
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3487
• WagamamaTV527
League of Legends
• Nemesis4833
• TFBlade930
Other Games
• imaqtpie937
• Shiphtur262
Upcoming Events
BSL: GosuLeague
2h 6m
PiGosaur Cup
6h 6m
The PondCast
15h 6m
Replay Cast
1d 4h
RSL Revival
1d 12h
herO vs Zoun
Classic vs Reynor
Maru vs SHIN
MaxPax vs TriGGeR
BSL: GosuLeague
2 days
RSL Revival
2 days
WardiTV Korean Royale
2 days
RSL Revival
3 days
WardiTV Korean Royale
3 days
[ Show More ]
IPSL
3 days
Julia vs Artosis
JDConan vs DragOn
RSL Revival
4 days
Wardi Open
4 days
IPSL
5 days
StRyKeR vs OldBoy
Sziky vs Tarson
Replay Cast
5 days
Monday Night Weeklies
5 days
Replay Cast
6 days
Wardi Open
6 days
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
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
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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...

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.