• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:32
CEST 12:32
KST 19:32
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Weekly Cups (June 30 - July 6): Classic Doubles0[BSL20] Non-Korean Championship 4x BSL + 4x China7Flash Announces Hiatus From ASL63Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event22
StarCraft 2
General
Weekly Cups (June 30 - July 6): Classic Doubles Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form?
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
ASL20 Preliminary Maps SC uni coach streams logging into betting site Player “Jedi” cheat on CSL Flash Announces Hiatus From ASL BW General Discussion
Tourneys
[BSL20] Grand Finals - Sunday 20:00 CET [BSL20] Non-Korean Championship 4x BSL + 4x China CSL Xiamen International Invitational The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread What do you want from future RTS games? Beyond All Reason
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 Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2024! Summer Games Done Quick 2025! Russo-Ukrainian War Thread
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread 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
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 669 users

The Big Programming Thread - Page 689

Forum Index > General Forum
Post a Reply
Prev 1 687 688 689 690 691 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
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
Spain17971 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
Spain17971 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
Spain17971 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
Poland17243 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
Poland17243 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
Poland17243 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
Hyrule19031 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 28m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Creator 99
StarCraft: Brood War
Hyuk 759
Pusan 491
Soma 457
Stork 309
Jaedong 205
ZerO 170
Sharp 160
Larva 134
sorry 129
sSak 98
[ Show more ]
Soulkey 98
Shine 65
yabsab 51
Aegong 39
Snow 39
Free 27
zelot 26
JulyZerg 25
Mind 24
IntoTheRainbow 10
ivOry 3
Dota 2
XcaliburYe567
XaKoH 528
syndereN92
Counter-Strike
shoxiejesuss689
x6flipin409
allub120
Super Smash Bros
Mew2King243
Other Games
Pyrionflax314
crisheroes257
SortOf150
rGuardiaN49
ZerO(Twitch)17
Organizations
Other Games
gamesdonequick28834
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2227
League of Legends
• HappyZerGling100
Other Games
• WagamamaTV166
Upcoming Events
Wardi Open
28m
Replay Cast
13h 28m
Sparkling Tuna Cup
23h 28m
WardiTV European League
1d 5h
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
1d 13h
The PondCast
1d 23h
WardiTV European League
2 days
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
uThermal 2v2 Circuit
2 days
Replay Cast
2 days
RSL Revival
2 days
ByuN vs SHIN
Clem vs Reynor
[ Show More ]
Replay Cast
3 days
RSL Revival
3 days
Classic vs Cure
FEL
4 days
RSL Revival
4 days
FEL
5 days
FEL
5 days
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
6 days
Liquipedia Results

Completed

BSL Season 20
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
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
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
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.