• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 20:38
CET 02:38
KST 10:38
  • 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 (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies3ComeBackTV's documentary on Byun's Career !11Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win4Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2
StarCraft 2
General
ComeBackTV's documentary on Byun's Career ! Team TLMC #5: Winners Announced! What's the best tug of war? The Grack before Christmas Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies
Tourneys
OSC Season 13 World Championship $5,000+ WardiTV 2025 Championship $100 Prize Pool - Winter Warp Gate Masters Showdow Sparkling Tuna Cup - Weekly Open Tournament Winter Warp Gate Amateur Showdown #1
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 505 Rise From Ashes Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement
Brood War
General
BW General Discussion How soO Began His ProGaming Dreams Klaucher discontinued / in-game color settings BGH Auto Balance -> http://bghmmr.eu/ Recommended FPV games (post-KeSPA)
Tourneys
[Megathread] Daily Proleagues [BSL21] LB SemiFinals - Saturday 21:00 CET [BSL21] WB & LB Finals - Sunday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Current Meta Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Mechabellum Stormgate/Frost Giant Megathread Beyond All Reason 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
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread 12 Days of Starcraft The Games Industry And ATVI Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced Where to ask questions and add stream?
Blogs
National Diversity: A Challe…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1415 users

The Big Programming Thread - Page 812

Forum Index > General Forum
Post a Reply
Prev 1 810 811 812 813 814 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.
Acrofales
Profile Joined August 2010
Spain18159 Posts
December 07 2016 14:41 GMT
#16221
Oh wait. When copying to run my own tests, I just saw that in your main method, pb is not a phonebook, it is a TreeMap<String, String>. That is, of course, only going to have <a, 3> in there after your 3 puts...
Yurie
Profile Blog Joined August 2010
11965 Posts
Last Edited: 2016-12-07 14:58:52
December 07 2016 14:45 GMT
#16222
On December 07 2016 23:41 Acrofales wrote:
Oh wait. When copying to run my own tests, I just saw that in your main method, pb is not a phonebook, it is a TreeMap<String, String>. That is, of course, only going to have <a, 3> in there after your 3 puts...


Right you are. I made a big mistake there. :/

On December 07 2016 23:40 Blitzkrieg0 wrote:
Show nested quote +
On December 07 2016 23:26 Yurie wrote:+ Show Spoiler +

On December 07 2016 23:18 Acrofales wrote:
Unless you have a very specific reason to use LinkedList, an arraylist is always better. But given that you want numbers to be unique, why not use a HashSet (which will give you most of the functionality you want)?

That said, it should affect performance, and not functionality.

However, I don't quite understand your debugging info. Your phonebook having size one before you add b seems correct: it has one entry: <a, LinkedList object>. Your linked list should have 3 values (1, 2, 3), not your map.


So nested HashSets instead of using a string, arraylist (or linkedlist)? I am not sure how that works but it might be easier since I am required to export it to a set. Else I assume I would have to do something like the following but with the size of the arraylist.
      try {
for(int i = 0; i < size-1; i++) {
set.add(count[i];
}



As for adding the numbers one by one I found the following on stackexchange that I will experiment a bit with:
String key = "mango";
int number = 42;
if (map.get(key) == null) {
map.put(key, new ArrayList<Integer>());
}
map.get(key).add(number);


I only get the last value 3 when I actually check the memory in the variables. So regardless that my code should return 2 it doesn't have the right thing in memory since my put code is wrong.

Edit, thanks for the replies people. I'll try working at it a bit before asking for help again. Great advice.


Sets are the smarter way to do it. A Set is just a List that can't have duplicate values. Having a duplicate phone number does not make sense. I was under the impression that you had to use a List for the assignment, but if you can choose then do use a Set instead of an ArrayList.


Seems to work in a short test code. Thanks for the idea. Now to get the actual thing to work, easier when I get the logic.

public class Testphoneb {
public static void main(String[] args) {
Map<String, Set<String>> pb = new HashMap<String, Set<String>>();
System.out.println("Size: " + pb.size());

Set<String> a = new HashSet<String>();
a.add("1");
a.add("2");
a.add("3");

Set<String> b = new HashSet<String>();
b.add("4");
pb.put("start", a);
pb.put("end", b);
System.out.println("Size: " + pb.size());
System.out.println("Get start: " + pb.get("start"));
System.out.println("Get end: " + pb.get("end"));
}
}

Output is now correct in the short test code on how it works:

Size: 0
Size: 2
Get start: [1, 2, 3]
Get end: [4]
Yurie
Profile Blog Joined August 2010
11965 Posts
Last Edited: 2016-12-07 15:43:05
December 07 2016 15:39 GMT
#16223
Got stuck on one last test case of the 26 groups of them and I can't see why it acts that way. Could somebody explain the logic so I can solve the problem? (It is still Java.) Fill() adds 1,2,3 to a, so three values in size. The numbers.add("4"); somehow adds to the main phonebook as well and I don't understand why.


public final void testFindNumbersNamesNoInternalReferencesReturned() {
fill();
Set<String> numbers = pb.findNumbers("a");
assertEquals("Wrong size for number set to a:", 3, pb.findNumbers("a").size());
numbers.add("4");
assertEquals("Reference to internal set returned. Wrong size for number set to a:", 3, pb.findNumbers("a").size());
assertFalse("Reference to internal set returned. Number found in phonebook: a", pb.findNumbers("a").contains("4"));
}


Referring to findNumbers that is a bit longer than it needs to be since I've been tinkering with it to try to solve it.
	public Set<String> findNumbers(String name) {
if(phoneBook.containsKey(name)){
Set<String> number = new HashSet<String>();
number = phoneBook.get(name);
return number;
}
else{
Set<String> number = new HashSet<String>();
return number;
}
}


phoneBook is already set as private, which I thought might be the problem even though it shouldn't be.

public class MapPhoneBook implements PhoneBook{
private Map<String, Set<String>> phoneBook;

public MapPhoneBook() {
phoneBook = new HashMap<String, Set<String>>();
}

Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-12-07 16:15:27
December 07 2016 16:02 GMT
#16224
--- Nuked ---
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2016-12-07 16:30:40
December 07 2016 16:29 GMT
#16225
Talked with a few game developers in AAA and Indie studios, and determined that C# with Unity is the right path for me to go(this is something I recommend anyone reading this for advice in their own decision does research into for themselves, as this is a personal decision based on my own strengths and weaknesses), going towards the goal of getting a job in an Indie game studio.

With this in mind, I'd love to know of what resources you guys might recommend for learning C# and Unity, specifically focusing on game programming, not the art at all.

So far I'm going to be using Unity's own free tutorials and this book on C#.
http://www.introprogramming.info/wp-content/uploads/2013/07/Books/CSharpEn/Fundamentals-of-Computer-Programming-with-CSharp-Nakov-eBook-v2013.pdf
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Acrofales
Profile Joined August 2010
Spain18159 Posts
December 07 2016 17:29 GMT
#16226
On December 08 2016 00:39 Yurie wrote:
Got stuck on one last test case of the 26 groups of them and I can't see why it acts that way. Could somebody explain the logic so I can solve the problem? (It is still Java.) Fill() adds 1,2,3 to a, so three values in size. The numbers.add("4"); somehow adds to the main phonebook as well and I don't understand why.


public final void testFindNumbersNamesNoInternalReferencesReturned() {
fill();
Set<String> numbers = pb.findNumbers("a");
assertEquals("Wrong size for number set to a:", 3, pb.findNumbers("a").size());
numbers.add("4");
assertEquals("Reference to internal set returned. Wrong size for number set to a:", 3, pb.findNumbers("a").size());
assertFalse("Reference to internal set returned. Number found in phonebook: a", pb.findNumbers("a").contains("4"));
}


Referring to findNumbers that is a bit longer than it needs to be since I've been tinkering with it to try to solve it.
	public Set<String> findNumbers(String name) {
if(phoneBook.containsKey(name)){
Set<String> number = new HashSet<String>();
number = phoneBook.get(name);
return number;
}
else{
Set<String> number = new HashSet<String>();
return number;
}
}


phoneBook is already set as private, which I thought might be the problem even though it shouldn't be.

public class MapPhoneBook implements PhoneBook{
private Map<String, Set<String>> phoneBook;

public MapPhoneBook() {
phoneBook = new HashMap<String, Set<String>>();
}



This. But to make your life easier, you can use a copy constructor.
BluzMan
Profile Blog Joined April 2006
Russian Federation4235 Posts
December 07 2016 19:07 GMT
#16227
Quick question to those already in the industry: do you really (the truth now!) write comments in your code? All the open source libraries have these docstrings and fancy annotations, but does your actual production code not meant for public eyes have any?
You want 20 good men, but you need a bad pussy.
Acrofales
Profile Joined August 2010
Spain18159 Posts
Last Edited: 2016-12-07 19:24:04
December 07 2016 19:23 GMT
#16228
There's production code not meant for others to see? You need to treat your future self as other people, because for choosing purposes you effectively are.

That said, I am pretty terrible at documenting my code and am off the belief that a method should do 1 thing and be named appropriately. If it does lots of other stuff it means that either the other stuff is necessary to do it's main purpose and otherwise unimportant (and only needs to be done if doing the method's stuff), or it was written by an idiot (that idiot may y have been me 2 weeks ago).

I only document when something will need to be fiddled with and is rather complicated and/or non-obvious. Other than that I use comments like post-its: todos, ideas for cleaning up, or refactoring, etc.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 07 2016 19:36 GMT
#16229
On December 08 2016 04:07 BluzMan wrote:
Quick question to those already in the industry: do you really (the truth now!) write comments in your code? All the open source libraries have these docstrings and fancy annotations, but does your actual production code not meant for public eyes have any?

It is fairly easy to enforce comments in a good IDE. Plus code reviews.
Comments are important. You have a team you work with, and you have to understand your own code 6 months from now.

Be careful though: pointless comments are bad, and overly verbose comments are bad too. Try to stick with the stuff that actually adds information.
If you have a good reason to disagree with the above, please tell me. Thank you.
tofucake
Profile Blog Joined October 2009
Hyrule19184 Posts
Last Edited: 2016-12-07 19:56:51
December 07 2016 19:54 GMT
#16230
On December 08 2016 04:07 BluzMan wrote:
Quick question to those already in the industry: do you really (the truth now!) write comments in your code? All the open source libraries have these docstrings and fancy annotations, but does your actual production code not meant for public eyes have any?

all the time. a few examples I've personally written:

        try {
$this->em = $this->getManager();
$this->verbose = $verbose;
$this->logger = $this->getContainer()->get('logger');
} catch (\Exception $e) {
// not really anything we can do here, since either the em set fails and logger isn't set,
// or logger fails and logger isn't set
// maybe we just cry here?
dump("something happened");
dump($e);
}



// at some point this should do something productive instead
$request_type = $this->getRequestType($request);


        $rule = $this->getRepository('SharedBundle:ProgramRule')->findActiveRule($dates, $program, $group->getId());
# findActiveRule returns the first rule it can find that matches everything, though the only reason there would be
# multiple is if one of us was futzing with the db


edit: one that was extremely confusing
        if (!is_array($contract->_contract_participant_fees)) {
return 0; # this should probably never happen, except it did, see TD-84
}
Liquipediaasante sana squash banana
RoomOfMush
Profile Joined March 2015
1296 Posts
December 07 2016 19:58 GMT
#16231
On December 08 2016 04:07 BluzMan wrote:
Quick question to those already in the industry: do you really (the truth now!) write comments in your code? All the open source libraries have these docstrings and fancy annotations, but does your actual production code not meant for public eyes have any?

Most code is simple boilerplate code. If the method and variable names are well chosen and descriptive, and the code itself is straight forward and simple, I dont commentate.
Once I use more complicated algorithms to calculate something, or when the code has a strange structure, I write comments explaining what is happening.

Whenever I catch myself doubting code I had written (having to think it over or test it out once more) I comment it just in case I might ever get into this situation again where I am not quite sure what that particular part does. For example when I am more "clever" then usual and come up with some funny data structure at 3 in the morning.
tofucake
Profile Blog Joined October 2009
Hyrule19184 Posts
December 07 2016 20:02 GMT
#16232
oh and one I didn't write but is all over because the people we outsourced the project to in the beginning suck:
    //$data contains all the changes to the row.
//$new is true if we're inserting a row, and false if we're saving it.
//If anything other than true is returned, validation fails.
//This means you may return an error code or string or anything.
//This is called before the validation rules defined in $_rules.
public static function _validate($data, $new = false)
{
return true;
}
Liquipediaasante sana squash banana
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2016-12-07 20:32:33
December 07 2016 20:32 GMT
#16233
I write way more comments at work than privately because we're required to put a comment on every single method. It would be enough to comment all the dll-public classes and methods and all the stuff that isn't immediately obvious. Also be brief. Ideally you are not required to comment more than that, because comments that don't add any value are a waste of time, can get out of sync with the code and create visual clutter. Which teaches you to ignore all comments, even the valuable ones. As much information as possible should be immediately obvious from the code by choosing good names and structuring the code well.

Still, always consider how hard a piece of code will be to understand for your colleague or you in 6 months. Heck, consider it for yourself, 6 months ago (or whatever time you were significantly less skilled). If someone might think a minute about, spend those 10 seconds and write a comment (after you verified that the code is already as clear as you can reasonably write it).
If you have a good reason to disagree with the above, please tell me. Thank you.
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
December 07 2016 20:47 GMT
#16234
On December 08 2016 05:02 tofucake wrote:
oh and one I didn't write but is all over because the people we outsourced the project to in the beginning suck:
    //$data contains all the changes to the row.
//$new is true if we're inserting a row, and false if we're saving it.
//If anything other than true is returned, validation fails.
//This means you may return an error code or string or anything.
//This is called before the validation rules defined in $_rules.
public static function _validate($data, $new = false)
{
return true;
}



validation is one of the most problematic topics in writing good code imo. Add multilingual support in error messages plus different clients and it gets huge.
Age of Mythology forever!
tofucake
Profile Blog Joined October 2009
Hyrule19184 Posts
December 07 2016 21:01 GMT
#16235
the data isn't actually validated, it just returns true
Liquipediaasante sana squash banana
BluzMan
Profile Blog Joined April 2006
Russian Federation4235 Posts
December 07 2016 21:26 GMT
#16236
Well, I'm asking because after several years of work I find myself avoiding annotating code more and more, and I realize that my inner desire contradicts the "best practices" in software world, and I want to find out if anyone else feels the same way. I actually feel pretty angry when I find comments in code written by others unless there's a specific hack that is really impossible to understand without them.

Whenever I read code, everything is structured, all the tokens are color-coded and it takes me but a small glance to understand what's going on. Furthermore, should something get changed, I've got a massive type system behind my back to halt my compiler if anything is forgotten. Comments are nothing like that. In an IDE, they are a structure-less gray blob that doesn't have any compile-time guarantees to even make sense, let alone tell the truth and be useful.

And they make simple code look complicated because they pollute so much space. Just look at this! This wall of text takes up so much visual space it's actually hard to see that this function just returns true for all input.

On December 08 2016 05:47 mantequilla wrote:
Show nested quote +
On December 08 2016 05:02 tofucake wrote:
oh and one I didn't write but is all over because the people we outsourced the project to in the beginning suck:
    //$data contains all the changes to the row.
//$new is true if we're inserting a row, and false if we're saving it.
//If anything other than true is returned, validation fails.
//This means you may return an error code or string or anything.
//This is called before the validation rules defined in $_rules.
public static function _validate($data, $new = false)
{
return true;
}



validation is one of the most problematic topics in writing good code imo. Add multilingual support in error messages plus different clients and it gets huge.


Plus, I've yet to see good auto-generated documentation. I guess C++ kinda skews my vision since I have the luxury of figuring out all the types just from reading the headers (python people must be pretty upset - documentation is needed to know what types functions expect), but all the good documentation I've read was obviously handwritten and went way beyond what typically comes out of a javadoc-like system.
You want 20 good men, but you need a bad pussy.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-12-07 21:41:58
December 07 2016 21:35 GMT
#16237
On December 08 2016 06:26 BluzMan wrote:
And they make simple code look complicated because they pollute so much space. Just look at this! This wall of text takes up so much visual space it's actually hard to see that this function just returns true for all input.


To me the comment makes it clear that it is a bug and needs to be changed. Anytime you do something that looks stupid it should be commented anyway like a validation always returning true. There should be an explanation for why that is needed if it was intentional.

It's nice to have a high level design of what you're working on including why and who made certain decisions so people can have a discussion beyond this is how it currently works.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Chocolate
Profile Blog Joined December 2010
United States2350 Posts
December 07 2016 21:45 GMT
#16238
What does a day at work look like for you guys? I'm interviewing at some places and trying to figure out what to expect or look for. I did see a prototypical intern schedule somewhere that was like "arrive at 8 am, brush up on work, eat breakfast" and then some more stuff and then "6pm, go to company event with mentors" and I knew to stay the fuck away.

But like what do you do in a day? How much coding (both in terms of time and amount of code written, not lines but functionality) actually gets done? This past summer I was more of a glorified sysadmin (and it was in a research setting too...) than anything so I didn't really get to write very much.
tofucake
Profile Blog Joined October 2009
Hyrule19184 Posts
December 07 2016 21:54 GMT
#16239
I do about 5 hours of coding most days out of an 8.5 hour day. There's an hour for lunch, 15 minute standup, maybe another meeting, and a bunch of googling
Liquipediaasante sana squash banana
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 07 2016 22:45 GMT
#16240
I don't really know how much actual coding I do. The largest portion of coding is thinking anyways, and I frequently answer questions of colleagues... hard to track how much time you think about your own problems and how much about your colleagues' problems.

Looking at it from the the other side: I have a 15 minute standup a day, I guess 30-60 minutes of scheduled meetings (some of these with customers) per day on average. And then maybe 1-2 hours of discussing stuff with colleages? Rough estimate. So I guess I'm at about 5 hours of coding (including necessary "research") too. Though this can range from 7.5 hours to less than an hour each single day.
If you have a good reason to disagree with the above, please tell me. Thank you.
Prev 1 810 811 812 813 814 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 8h 22m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
elazer 294
Vindicta 92
StarCraft: Brood War
Shuttle 697
Stork 458
GoRush 46
yabsab 42
NaDa 23
Dota 2
LuMiX1
Counter-Strike
minikerr26
Heroes of the Storm
Khaldor195
Other Games
tarik_tv6865
summit1g6705
JimRising 331
ViBE156
XaKoH 113
Mew2King85
Organizations
Other Games
gamesdonequick1429
BasetradeTV49
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• musti20045 32
• Kozan
• Migwel
• sooper7s
• AfreecaTV YouTube
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• blackmanpl 45
• Pr0nogo 1
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2921
League of Legends
• Doublelift6094
• Stunt319
Other Games
• imaqtpie2991
Upcoming Events
Sparkling Tuna Cup
8h 22m
Krystianer vs Classic
TriGGeR vs SKillous
Percival vs Ryung
ByuN vs Nicoract
OSC
16h 22m
BSL 21
18h 22m
Cross vs Dewalt
Replay Cast
1d 7h
Wardi Open
1d 10h
OSC
2 days
Solar vs MaxPax
ByuN vs Krystianer
Spirit vs TBD
OSC
5 days
Korean StarCraft League
6 days
OSC
6 days
OSC
6 days
Liquipedia Results

Completed

Escore Tournament S1 - W1
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL Season 21
CSL Season 19: Qualifier 2
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1 - W2
Escore Tournament S1 - W3
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
OSC Championship Season 13
Nations Cup 2026
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
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.