• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:22
CEST 13:22
KST 20:22
  • 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
[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists16[ASL21] Ro16 Preview Pt1: Fresh Flow9[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0
Community News
2026 GSL Season 1 Qualifiers13Maestros of the Game 2 announced72026 GSL Tour plans announced14Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid24
StarCraft 2
General
Maestros of the Game 2 announced Team Liquid Map Contest #22 - The Finalists MaNa leaves Team Liquid 2026 GSL Tour plans announced Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool
Tourneys
2026 GSL Season 1 Qualifiers GSL CK: More events planned pending crowdfunding RSL Revival: Season 5 - Qualifiers and Main Event Sparkling Tuna Cup - Weekly Open Tournament Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 522 Flip My Base The PondCast: SC2 News & Results Mutation # 521 Memorable Boss Mutation # 520 Moving Fees
Brood War
General
ASL21 General Discussion Data needed BGH Auto Balance -> http://bghmmr.eu/ Any progamer "explanation" videos like this one? ASL21 Strategy, Pimpest Plays Discussions
Tourneys
[ASL21] Ro16 Group D [Megathread] Daily Proleagues [ASL21] Ro16 Group C [ASL21] Ro16 Group B
Strategy
Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend? Fighting Spirit mining rates
Other Games
General Games
Dawn of War IV Nintendo Switch Thread Starcraft Tabletop Miniature Game General RTS Discussion Thread Battle Aces/David Kim RTS Megathread
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
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story Cricket [SPORT]
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1724 users

The Big Programming Thread - Page 832

Forum Index > General Forum
Post a Reply
Prev 1 830 831 832 833 834 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.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-01-29 04:04:38
January 29 2017 03:43 GMT
#16621
I'm 90% sure my last 2 places of work had no while loops explicitly in our coding guidelines. Say no to while loops!

And also to declare as close to usage as possible. I thought we've moved on from C89! For a project I spent some time hacking around things to get c99/gnu99 working because I wasn't going to live with only declaring at the start of functions.
There is no one like you in the universe.
Hanh
Profile Joined June 2016
146 Posts
January 29 2017 04:18 GMT
#16622
That code,


int i = 0;

...

while (i++ < 10) {
// do stuff
}


is asking for trouble. Some guy can change 'i' between the initialization and the while loop or inside the loop itself.

If your language permits it, something like


for i in 0 to 9 do
...
done


It's shorter, clearer and safer ('i' is immutable).
tofucake
Profile Blog Joined October 2009
Hyrule19203 Posts
January 29 2017 05:05 GMT
#16623
"some guy"? Do you have random people working on your codebase? Doing while loops like that is perfectly acceptable, and was even required by C until C99 or something like that.
Liquipediaasante sana squash banana
Hanh
Profile Joined June 2016
146 Posts
January 29 2017 06:06 GMT
#16624
Yeah - I don't review/control all the code that is added to my code base. Write under K&R C rules if you want, but these bugs could have been avoided easily. Writing code that junior developers will find too troublesome to break is my defense.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
January 29 2017 07:07 GMT
#16625
On January 29 2017 09:50 Manit0u wrote:
Show nested quote +
On January 29 2017 06:39 spinesheath wrote:
The ++ operators should never have been created in the first place. The potential for legitimate use is greatly outweighed by people trying to be "clever" and failing hard.


It's useful when you want to replace for loops with while loops (which is done behind the scenes by the compiler anyway, since for is just an alias for while). It saves you but a line of code compared to the proper while loop, but if your project will have thousands of those, it's thousands of lines saved.

ex:


for (int i = 0; i < 10; i++) {
// do stuff
}

// ^ translates to
int i = 0;

while (i < 10) {
// do stuff
i += 1;
}


Now, I prefer to write it this way:

int i = 0;

while (i++ < 10) {
// do stuff
}


I prefer to use while over for whenever I can, mostly because I like to declare and initialize all the variables at the beginning of a function. Makes it easier to debug later on, even if it isn't the most efficient thing to do.

I don't see any debugging advantage at all with that. Nowadays it is common practice to declare variables as close to usage as possible, ideally right where they are initialized.

Also I much prefer to use a for loop in this case because it much clearer that the i is just a loop variable, going from some a to some b. Whenever I see a while loop like that I double check the progression of i because usually something other than simple increment is happening somewhere in there, which is why the for loop became awkward and was replaced with a while.

I have no issue with 1000 extra lines if that means that I don't mangle 2000 separate instructions into 1000 lines. You're incrementing and comparing in a single line. Sure it isn't so bad here if you use it as a fixed pattern, but unlike a for loop you can't even freely switch between pre- and postincrement here.
If you have a good reason to disagree with the above, please tell me. Thank you.
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-29 08:32:18
January 29 2017 08:32 GMT
#16626
Besides what the others have said above, the two loops Manit0u has shown are not even equal in functionality. In the second while-loop the "do stuff" will happen after i has been incremented. In the for-loop and the first while-loop it happens before. I would call that a mild case of error potential.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
January 29 2017 08:36 GMT
#16627
On January 29 2017 17:32 RoomOfMush wrote:
Besides what the others have said above, the two loops Manit0u has shown are not even equal in functionality. In the second while-loop the "do stuff" will happen after i has been incremented. In the for-loop and the first while-loop it happens before. I would call that a mild case of error potential.

Good point. I didn't even realize that. And considering I was talking about this exact construct and still missed it, I'd consider it a rather serious case of error potential.
If you have a good reason to disagree with the above, please tell me. Thank you.
Acrofales
Profile Joined August 2010
Spain18271 Posts
January 29 2017 09:30 GMT
#16628
On January 29 2017 07:34 Manit0u wrote:
Show nested quote +
On January 29 2017 05:24 Acrofales wrote:
But why would you ever type a = a++; (except as a typo from ignorance)? The whole point of a++ is that it's shorthand for incrementing by 1. So if you use ++, you write it:

#include <stdio.h>

int main() {
int a = 10;
do {
printf("Value of a: %d\n", a);
a++ ;

} while ( a <20 );

return 0;
}

And voila, it works fine. The moment you start writing things with a = <do something with a>, you have to worry about operator precedence (in fact, any time you use multiple operators you have to think about that).



#include <stdio.h>

int main(void)
{
int a = 10;

do {
printf("Value of a: %d\n", a);
} while (a++ < 20);

return 0;
}


That's how you do it (if you really want to use the ++ operator)

Pretty sure that will loop 10 times, whereas the initial code loops 9 times, because I *think* a < 20 has higher precedence than ++, so for that to work, you'd have to write it


#include <stdio.h>

int main(void)
{
int a = 10;

do {
printf("Value of a: %d\n", a);
} while (++a < 20);

return 0;
}


And because of subtle bugs like this, I avoid concatenating ++ with other operators. I only use it as shorthand for i = i + 1, as a separate statement, or in a for loop in languages that don't support more modern syntax.
Hanh
Profile Joined June 2016
146 Posts
January 29 2017 11:13 GMT
#16629
Isn't it ironic when what you recommend to do to avoid bugs is a bug itself?
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-29 11:54:10
January 29 2017 11:53 GMT
#16630
On January 29 2017 20:13 Hanh wrote:
Isn't it ironic when what you recommend to do to avoid bugs is a bug itself?

Programming has a lot to do with personal experiences and confidence. People re-use code (and libraries & technologies) they have used before. It could very well be that Manit0u has more confidence in the second while-loop and that is why he uses it all the time. For him this may improve reliability & readability.
The only problem comes when you suddenly have to work in a team where each member is used to write things differently. This is when things can get messy. A good company will try to counteract this problem by imposing coding guidelines and force all employees to write these loops the same way to make sure nobody makes a stupid mistake when working with the code of somebody else.

But when you are working alone or with people who do things the same way as you do, you can do pretty much anything you feel comfortable with.
Acrofales
Profile Joined August 2010
Spain18271 Posts
January 29 2017 21:53 GMT
#16631
Nvm, my post above is wrong :p But I stand by my point that it's confusing :p
Thaniri
Profile Blog Joined March 2011
1264 Posts
Last Edited: 2017-01-30 00:59:23
January 30 2017 00:04 GMT
#16632
Can anyone help me with a PHP question? (school question if you want to ignore those):

Im creating a login/create account form and trying to hash my passwords. When I'm salting + hashing a password what do I need to store in the database? Right now my database looks like: customer(cID, cHash, cEmail, cLname, cFname, cWallet)

So when a user creates an account I grab all the form inputs they have, hash+salt the password and store it in the cHash column.

Now when they want to login, how do I change their inputted password to the same thing as cHash?
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
January 30 2017 00:30 GMT
#16633
You need to add a column to store their salt into your database. When the user enters their password into the form you add the salt and hash it. If the proper password was entered that will match the hash stored in the database.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Thaniri
Profile Blog Joined March 2011
1264 Posts
Last Edited: 2017-01-30 00:57:35
January 30 2017 00:43 GMT
#16634
Okay thanks, I should be able to do it now. Going to have to rewrite some methods.

edit: works like a charm
phar
Profile Joined August 2011
United States1080 Posts
January 30 2017 01:44 GMT
#16635
On January 29 2017 14:05 tofucake wrote:
"some guy"? Do you have random people working on your codebase? Doing while loops like that is perfectly acceptable, and was even required by C until C99 or something like that.

You should generally always assume that your code is going to be read more than it is written, and modified many times down the road by others.

In related news, herein lies the usefulness of automated testing infrastructure.
Who after all is today speaking about the destruction of the Armenians?
Manit0u
Profile Blog Joined August 2004
Poland17731 Posts
Last Edited: 2017-01-30 01:53:29
January 30 2017 01:46 GMT
#16636
On January 30 2017 09:30 Blitzkrieg0 wrote:
You need to add a column to store their salt into your database. When the user enters their password into the form you add the salt and hash it. If the proper password was entered that will match the hash stored in the database.


Fuck no! Your solution is good but for more general use, not PHP itself.

With PHP you should use the password_hash() and password_verify() functions. PHP 7 has even deprecated the 'salt' option for those... What it does is use bcrypt (at the moment, might change the default if something stronger will come along and be established enough - like Argon2) to hash your password, generates salt automatically and stores it inside the password itself (as of PHP 5.5 default algo is bcrypt and cost is 10).

So, what you need in the db (absolutely minimal setup):


TABLE: users
COLUMNS: id, username, password


Then, in your code:


class User
{
protected $id;
protected $username;
protected $password;

public function setPassword($password)
{
$this->password = password_hash($password);
}

public function getPassword()
{
return $this->password;
}

public function passwordValid($password)
{
return password_verify($password, $this->password);
}
}


And that's it. You never know what the plaintext password is, or what the salt is. With this approach you can also use stuff like password_needs_rehash() in case you change your hashing algo. It's dead easy to implement a simple way to gradually update your user passwords as necessary without having to do some complex logic and database juggling.

Edit:

Also, to the posters above, I was wrong about those loops but I was up for 23 hours at the time of writing that and my mind just wandered random places...
Time is precious. Waste it wisely.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
January 30 2017 02:13 GMT
#16637
Why does php obscure the salts? That just seems like a fundamental misunderstanding of the purpose of salts.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Hanh
Profile Joined June 2016
146 Posts
January 30 2017 02:57 GMT
#16638
It doesn't obscure it. It puts it in the returned value before the actual hash value. That's to avoid the mistake of forgetting to store the salt and cost separately.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2017-01-30 05:05:28
January 30 2017 05:05 GMT
#16639
Could any of you please tell me why I can access the local host version of my server but cannot access it through my external IP? I allowed traffic through the firewall according to this guide.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
January 30 2017 05:14 GMT
#16640
--- Nuked ---
Prev 1 830 831 832 833 834 1032 Next
Please log in or register to reply.
Live Events Refresh
RSL Revival
10:00
Season 5 Korea Qualifier
Solar vs SHINLIVE!
Classic vs Percival
Ryung 793
CranKy Ducklings SOOP194
CranKy Ducklings182
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Ryung 793
Lowko246
SortOf 140
StarCraft: Brood War
Britney 22467
Calm 6175
Sea 2827
Jaedong 1342
Horang2 958
Hyuk 778
Leta 313
BeSt 294
Mini 236
Soma 230
[ Show more ]
Stork 203
actioN 201
Rush 152
Last 128
Light 128
Larva 121
Snow 106
Dewaltoss 91
ZerO 87
Soulkey 77
Pusan 72
ToSsGirL 68
Sacsri 65
Killer 56
JYJ 53
Hyun 47
Mind 40
Sharp 38
sSak 35
Backho 32
ggaemo 26
sorry 26
[sc1f]eonzerg 25
IntoTheRainbow 24
hero 22
Bale 20
HiyA 19
zelot 17
yabsab 17
soO 16
Hm[arnc] 14
scan(afreeca) 12
Shine 8
Shinee 6
Movie 3
Dota 2
Gorgc3016
Counter-Strike
SPUNJ248
Super Smash Bros
Mew2King146
Other Games
singsing1583
B2W.Neo425
XaKoH 224
Pyrionflax177
Trikslyr128
DeMusliM82
KnowMe71
RotterdaM56
QueenE11
ZerO(Twitch)7
Organizations
Dota 2
PGL Dota 2 - Main Stream9713
Other Games
gamesdonequick645
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• TFBlade1393
• Jankos1149
Upcoming Events
Replay Cast
12h 38m
The PondCast
22h 38m
KCM Race Survival
22h 38m
WardiTV Map Contest Tou…
23h 38m
Gerald vs herO
Clem vs Cure
ByuN vs Solar
Rogue vs MaxPax
ShoWTimE vs TBD
OSC
1d 3h
CranKy Ducklings
1d 12h
Escore
1d 22h
RSL Revival
2 days
Replay Cast
2 days
WardiTV Map Contest Tou…
2 days
[ Show More ]
Universe Titan Cup
2 days
Rogue vs Percival
Ladder Legends
3 days
uThermal 2v2 Circuit
3 days
BSL
3 days
Sparkling Tuna Cup
3 days
WardiTV Map Contest Tou…
3 days
Ladder Legends
4 days
BSL
4 days
Replay Cast
4 days
Replay Cast
4 days
Wardi Open
4 days
Afreeca Starleague
4 days
Soma vs TBD
Monday Night Weeklies
5 days
Replay Cast
5 days
Afreeca Starleague
5 days
TBD vs YSC
Replay Cast
6 days
Liquipedia Results

Completed

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

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
StarCraft2 Community Team League 2026 Spring
WardiTV TLMC #16
Nations Cup 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W4
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
RSL Revival: Season 5
2026 GSL S1
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
BLAST Rivals Spring 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.