• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 13:20
CEST 19:20
KST 02:20
  • 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
Code S Season 1 - RO8 Preview4[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10
Community News
Maestros of The Game 2 announcement and schedule !7Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event12Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25
StarCraft 2
General
Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results
Tourneys
Maestros of The Game 2 announcement and schedule ! GSL Code S Season 1 (2026) Sea Duckling Open (Global, Bronze-Diamond) RSL Revival: Season 5 - Qualifiers and Main Event Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
Tulbo's ASL S21 Ro8 Post-Review Why there arent any 256x256 pro maps? Do we have a pimpest plays list? BGH Auto Balance -> http://bghmmr.eu/ (Spoiler) Asl ro8 D winner interview
Tourneys
Escore Tournament StarCraft Season 2 [ASL21] Ro8 Day 4 Small VOD Thread 2.0 [BSL22] RO16 Group Stage - 02 - 10 May
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread OutLive 25 (RTS Game) Dawn of War IV
Dota 2
The Story of Wings Gaming
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
European Politico-economics QA Mega-thread US Politics Mega-thread The Letting Off Steam Thread Canadian Politics Mega-thread Russo-Ukrainian War Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
How EEG Data Can Predict Gam…
TrAiDoS
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1245 users

The Big Programming Thread - Page 150

Forum Index > General Forum
Post a Reply
Prev 1 148 149 150 151 152 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.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-07-10 01:35:11
July 10 2012 01:33 GMT
#2981
On July 09 2012 13:00 Azerbaijan wrote:
I'm working on learning C and I made this simple number guessing game. I'm curious about the length of what I wrote and if it actually needs to tbe this long. I'm sure theres a way to compress it, maybe with functions, but im not quite there yet. I do want to know if this looks ok as far as clarity and use of functions goes. I know that scanf() is not a good choice but I'm still working on figuring out getchar() as an alternative, it still seems really abstract to me, its mostly just that that data types of confusing I think. I did manage to use getchar() and putchar() to spit out the ascii value of a character for me. SO basically i'm still a total noob but I'm having fun.

You don't need to compress it; it looks fine.

What would be more important though is just learning about the different data types and control structures (loops, if statements, switch statements, functions). scanf is perfectly fine for gathering user input when you're just learning to code. getchar will simply retrieve the first letter in the input buffer, and it waits for something to be placed into the input buffer if it is empty (things are placed into the input buffer when enter is pressed in a console program). Since getchar returns a single character you can actually just create a loop with getchar to read all the characters in the input buffer until a newline character is reached -- this reads a line from the input buffer:


char i;
while(i = getchar( ); i != '\n'; i = getchar( )) // Read each character, stop when find '\n' newline
{
printf( "%c", i ); // print retrieved characters back to the user
}


The above code will read a single line of user input and then print the line back to the user.
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
July 10 2012 01:34 GMT
#2982
On July 09 2012 16:53 Morfildur wrote:
Show nested quote +
On July 09 2012 16:22 opsayo wrote:
not a big fan of using ? for if statements

readability > conciseness imo :-)


If you add whitespace, that single line is a lot more readable than


if (guess < number) {
lowhigh_text = "low";
} else {
lowhigh_text = "high";
}


It always depends on how it's used. With the ternary ?: operator, it's clear that the variable gets assigned either value. In the if/else case you have to check each block to check if it's really the same variable that gets assigned.

While maintaining and repairing some of our legacy code, I got caught several times by code like:


if (a == b) {
temp = x;
} else {
tmp = y;
}




which is why you should use meaningful names, and not "temp" :D but yeah, the occasional ?: can replace a lot of other infrastructure code in some places.
Gold isn't everything in life... you need wood, too!
Ultraliskhero
Profile Joined April 2010
Canada249 Posts
July 17 2012 22:06 GMT
#2983
Hi guys, I have a question about my program in Python.

But first, can someone tell me how to make the block where I can post code properly? Like what tags I need to use? right now I don't even know how to indent, because extra spaces don't show up in my post, so I will not post any code for now.

I know C/C++ but I've just learned a bit of python(Very Noob) and I'm trying to create a tree in python.
It's not a binary tree or anything, and there is no order. Each treeNode simply has a list of treeNodes.

So first I create a treeNode object as the head, and it contains a list called "children". I have another list that contains three treeNodes(I will call them pNodes), and I used a for loop to add each of these three pNodes into the list called "children" that belongs to the treeNode that was created as the head.

I tried to debug my code with print statements and found that when I said:
treeNode.children.append(pNode)

treeNode.children[0] will be pNode, but for some reason, pNode.childen[0] also turned into pNode.
pNode.children is originally an empty list before the append, but for some reason a reference to itself was created.
Also, treeNode and pNode are definitely different objects.

Sorry I feel like my explanation is useless without posting the code, but does anyone have any guesses on what the problem may be?

The only language I know is C/C++ and it bugs me how python doesn't have pointers, I just don't know how anything works internally with python. Any help would be appreciated.

Thanks!
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-07-17 23:48:47
July 17 2012 23:46 GMT
#2984
Integer promotion is the number one cause of premature deaths in babies as young as –2147483647 years old.
Any sufficiently advanced technology is indistinguishable from magic
acidfreak
Profile Joined November 2010
Romania352 Posts
July 17 2012 23:49 GMT
#2985
On July 18 2012 08:46 RoyGBiv_13 wrote:
Integer promotion is the number one cause of premature deaths in babies as young as –2147483647.


But not 64bit integers!
You can't out-think the swarm, you can't out-maneuver the swarm, and you certainly can't break the morale of the swarm.
tec27
Profile Blog Joined June 2004
United States3702 Posts
July 18 2012 00:56 GMT
#2986
On July 18 2012 07:06 Ultraliskhero wrote:
Hi guys, I have a question about my program in Python.

But first, can someone tell me how to make the block where I can post code properly? Like what tags I need to use? right now I don't even know how to indent, because extra spaces don't show up in my post, so I will not post any code for now.

I know C/C++ but I've just learned a bit of python(Very Noob) and I'm trying to create a tree in python.
It's not a binary tree or anything, and there is no order. Each treeNode simply has a list of treeNodes.

So first I create a treeNode object as the head, and it contains a list called "children". I have another list that contains three treeNodes(I will call them pNodes), and I used a for loop to add each of these three pNodes into the list called "children" that belongs to the treeNode that was created as the head.

I tried to debug my code with print statements and found that when I said:
treeNode.children.append(pNode)

treeNode.children[0] will be pNode, but for some reason, pNode.childen[0] also turned into pNode.
pNode.children is originally an empty list before the append, but for some reason a reference to itself was created.
Also, treeNode and pNode are definitely different objects.

Sorry I feel like my explanation is useless without posting the code, but does anyone have any guesses on what the problem may be?

The only language I know is C/C++ and it bugs me how python doesn't have pointers, I just don't know how anything works internally with python. Any help would be appreciated.

Thanks!

Can't help you with your python, but to post code you can simply surround it with [ code][/code] tags. That will preserve spacing and use monospaced font
Can you jam with the console cowboys in cyberspace?
Ultraliskhero
Profile Joined April 2010
Canada249 Posts
July 19 2012 19:03 GMT
#2987
@tec27 Thanks man! Now I can post some code =D

Ok so I wrote a small python program that demonstrates my problem and was wondering if anyone here can explain to me what is happening in my program.


class testNode:
string = ""

children = []

def __init__(self, _string):
self.string = _string


firstNode = testNode("first")
secondNode = testNode("second")

treeHead = testNode("Head")
treeHead.children.append(firstNode)

print treeHead.children[0].string
print firstNode.children[0].string
print secondNode.children[0].string



So in the program above, I made my treeNode class, and created three objects. I then appended firstNode to treeHead's children list. In the subsequent three print statements. I expect the first one to print "first" because the firstNode was appended to treeHead's children. However, I expect the next two print statements to fail because the children list in firstNode and secondNode should be empty.

My problem is that this is not the case, and that the last two print statements both also prints "first". It seems to me that the list called children in my class was made virtual or something. Anyways can anyone explain to me this behaviour? I'm very noob with python, and only know C/C++

Thanks all!
supereddie
Profile Joined March 2011
Netherlands151 Posts
Last Edited: 2012-07-19 19:37:51
July 19 2012 19:37 GMT
#2988
http://docs.python.org/tutorial/classes.html

You've declared children (and string) as a class member, not an instance member like so:

class testNode:
def __init__(self, _string):
self.string = _string
self.children = []


"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
Ultraliskhero
Profile Joined April 2010
Canada249 Posts
July 20 2012 21:14 GMT
#2989
@supereddie

Thanks man! My program works now. This python syntax looks so weird to me, at a glance it looks like the class has only a constructor and no data members lol.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
July 20 2012 21:26 GMT
#2990
On July 21 2012 06:14 Ultraliskhero wrote:
@supereddie

Thanks man! My program works now. This python syntax looks so weird to me, at a glance it looks like the class has only a constructor and no data members lol.

That sort of is true, the instance of the class has data members, but the class itself only has a constructor method.
heroyi
Profile Blog Joined March 2009
United States1064 Posts
July 23 2012 21:21 GMT
#2991
I want to get into doing open source projects but can't seem to figure my way around. How does one begin working on an open source project (debugging and patches)? Do you just try to create a project on your own? How do you join/find a project before it begins? Do you need a certain level of expertise to start on one(I am personally a noob at c++)?

I am sorry if I seem ignorant. It seems like an overwhelming topic and I was unlucky to find only vague answers on google :/

tl;dr
I am interested in getting experience in opensource projects for experience and building my portfolio however I am still a "nub" in the programming community in c++. Have explored the concept/topic but still unsure and overwhelmed by the degree of knowledge it seems to require to start debugging/patching/working on an opensource...How do I get rid of that feeling of fear and being useless(I wouldn't even know how to find bugs let alone fix them)?
wat wat in my pants
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-07-23 21:43:45
July 23 2012 21:43 GMT
#2992
On July 24 2012 06:21 heroyi wrote:
I want to get into doing open source projects but can't seem to figure my way around. How does one begin working on an open source project (debugging and patches)? Do you just try to create a project on your own? How do you join/find a project before it begins? Do you need a certain level of expertise to start on one(I am personally a noob at c++)?

I am sorry if I seem ignorant. It seems like an overwhelming topic and I was unlucky to find only vague answers on google :/

tl;dr
I am interested in getting experience in opensource projects for experience and building my portfolio however I am still a "nub" in the programming community in c++. Have explored the concept/topic but still unsure and overwhelmed by the degree of knowledge it seems to require to start debugging/patching/working on an opensource...How do I get rid of that feeling of fear and being useless(I wouldn't even know how to find bugs let alone fix them)?

I'd say you should just do you own small projects, create tools and various applications to do different things. If you want to help work on Mozilla or something I'd feel you'd need a lot more depth in your programming skillset. You can then release the things you write as open source. That's what I'm doing
snively
Profile Blog Joined August 2011
United States1159 Posts
July 24 2012 20:20 GMT
#2993
lets say i have an integer that stores one of 4 flags. depending on the flag, i want my code to perform 4 different actions

whats the difference between using a switch and an if else if ladder?
is one of them better to use than the other?

thanks in advance.
My religion is Starcraft
Denar
Profile Blog Joined March 2011
France1633 Posts
July 24 2012 20:47 GMT
#2994
On July 25 2012 05:20 snively wrote:
lets say i have an integer that stores one of 4 flags. depending on the flag, i want my code to perform 4 different actions

whats the difference between using a switch and an if else if ladder?
is one of them better to use than the other?

thanks in advance.


It will depend on your language and your compiler, but I guess you ask this in terms of performance ? (Because apart from that, they both behave in the same way).

A switch statement can be optimized by your compiler into a jump table, which turns it into a single compare and a jump (in Assembly), instead of all the successive comparisons that an if/else if ladder creates.
This will happen mostly with simple switch statements with no default: value (and is compiler/language dependent).
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
July 24 2012 21:01 GMT
#2995
On July 25 2012 05:20 snively wrote:
lets say i have an integer that stores one of 4 flags. depending on the flag, i want my code to perform 4 different actions

whats the difference between using a switch and an if else if ladder?
is one of them better to use than the other?

thanks in advance.

When you say flags it sounds like you're talking about a bitfield with setting the bits for flags. In that case you'd need to use the and & operator, and can't really use a switch statement unless you were detecting combinations of bit patterns, instead of just the separate bits.

Nobody here is going to know what is faster, as it depends on the code you write and the compiler you use. You can stress test it yourself to figure out what is faster for you.
snively
Profile Blog Joined August 2011
United States1159 Posts
July 24 2012 21:10 GMT
#2996
Denar and CecilSunkure,
i was trying to ask if either one were better than the other in terms of readability and convention
(as in, using while loops instead of goto statements)
but i guess it doesnt really matter
im not doing anything where i would need to care so much about speed

thanks anyway!
My religion is Starcraft
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
July 24 2012 21:28 GMT
#2997
On July 25 2012 06:10 snively wrote:
Denar and CecilSunkure,
i was trying to ask if either one were better than the other in terms of readability and convention
(as in, using while loops instead of goto statements)
but i guess it doesnt really matter
im not doing anything where i would need to care so much about speed

thanks anyway!

Either one is fine

I myself like switches more.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-07-24 21:34:05
July 24 2012 21:33 GMT
#2998
On July 25 2012 05:20 snively wrote:
lets say i have an integer that stores one of 4 flags. depending on the flag, i want my code to perform 4 different actions

whats the difference between using a switch and an if else if ladder?
is one of them better to use than the other?

thanks in advance.


if flags can coexist, such as READ & WRITE....
+ Show Spoiler +

#define FLAG_ONE
#define FLAG_TWO
#define FLAG_THREE
#define FLAG_FOUR

void do_something(int flags)
{
if(flags | FLAG_ONE)

if(flags | FLAG_TWO)

...
}



Otherwise:

+ Show Spoiler +
use a switch & case statement
Any sufficiently advanced technology is indistinguishable from magic
Frigo
Profile Joined August 2009
Hungary1023 Posts
July 24 2012 22:55 GMT
#2999
It's a good idea to use enums and switch statements because using integers for this job only creates confusion and errors.
http://www.fimfiction.net/user/Treasure_Chest
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
July 24 2012 23:01 GMT
#3000
^^ Definitely enums and switch statements for conciseness and readability.
Undefeated TL Tecmo Super Bowl League Champion
Prev 1 148 149 150 151 152 1032 Next
Please log in or register to reply.
Live Events Refresh
Big Brain Bouts
16:00
#115
Fjant vs Bly
Serral vs Shameless
RotterdaM1693
TKL 174
IndyStarCraft 127
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 1693
TKL 174
IndyStarCraft 127
BRAT_OK 70
CosmosSc2 21
StarCraft: Brood War
Britney 27693
Bisu 2467
EffOrt 909
Stork 489
Larva 427
ggaemo 356
actioN 299
firebathero 285
Rush 233
Soulkey 227
[ Show more ]
ZerO 225
Hyuk 185
hero 141
Dewaltoss 89
Hyun 67
Sharp 63
Sea.KH 41
Pusan 38
Barracks 37
HiyA 23
sorry 21
Rock 21
soO 19
Shine 13
GoRush 12
ajuk12(nOOB) 9
Terrorterran 8
Dota 2
Gorgc6993
monkeys_forever375
XaKoH 59
Counter-Strike
fl0m1585
byalli516
Heroes of the Storm
MindelVK15
Other Games
FrodaN1956
qojqva1915
singsing1700
Liquid`RaSZi1139
Beastyqt626
ceh9421
B2W.Neo406
KnowMe194
ArmadaUGS120
QueenE110
Mew2King63
UpATreeSC53
Trikslyr50
C9.Mang036
ZerO(Twitch)18
fpsfer 1
Organizations
Other Games
gamesdonequick2418
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 17 non-featured ]
StarCraft 2
• Adnapsc2 1
• IndyKCrew
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• HerbMon 25
• FirePhoenix5
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• lizZardDota267
League of Legends
• Nemesis4526
• TFBlade1124
Other Games
• Shiphtur255
Upcoming Events
OSC
4h 40m
The PiG Daily
5h 40m
Maru vs Rogue
TBD vs Classic
herO vs Solar
ByuN vs Solar
Replay Cast
6h 40m
CranKy Ducklings
16h 40m
RSL Revival
16h 40m
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
17h 40m
Krystianer vs TriGGeR
Cure vs Rogue
SC Evo League
19h 40m
uThermal 2v2 Circuit
21h 40m
BSL
1d 1h
Artosis vs TerrOr
spx vs StRyKeR
Replay Cast
1d 6h
[ Show More ]
Sparkling Tuna Cup
1d 16h
RSL Revival
1d 16h
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
1d 17h
BSL
2 days
Dewalt vs DragOn
Aether vs Jimin
GSL
2 days
Afreeca Starleague
2 days
Soma vs Leta
Wardi Open
2 days
Monday Night Weeklies
2 days
OSC
3 days
CranKy Ducklings
3 days
Afreeca Starleague
3 days
Light vs Flash
Replay Cast
4 days
Replay Cast
5 days
The PondCast
5 days
Replay Cast
6 days
RSL Revival
6 days
Liquipedia Results

Completed

Proleague 2026-05-05
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 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

Upcoming

KK 2v2 League Season 1
BSL 22 Non-Korean Championship
YSL S3
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
BLAST Bounty Summer 2026: Closed Qualifier
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 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.