• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:37
CEST 15:37
KST 22:37
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)46Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) [D] Wireframe Casting Removed Clem: "I don't have that much hope in Blizzard" Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken?
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
ASL22 General Discussion BW General Discussion Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) Etiquete rules in Asl? Recent recommended BW games
Tourneys
[Megathread] Daily Proleagues Escore Tournament - Season 3 Small VOD Thread 2.0 [IPSL] Spring 2026 Grand Finals - This Weekend!
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Path of Exile General RTS Discussion Thread Nintendo Switch Thread Beyond All Reason Stormgate/Frost Giant Megathread
Dota 2
Looking for a Dota Mentor 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
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread The Games Industry And ATVI Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8828 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
Hyrule19228 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
Spain18375 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
Spain18375 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
Poland17794 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
Epic.LAN
13:00
Epic.LAN 48 Playoff Stage
epiclan23
Liquipedia
WardiTV Invitational
12:00
Summer Cup 2026 - Group A
WardiTV785
LiquipediaDiscussion
CranKy Ducklings
10:00
Master Swan Open #105
CranKy Ducklings58
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko528
Rex 109
BRAT_OK 101
MindelVK 27
RushiSC 22
StarCraft: Brood War
Calm 8092
Rain 2270
Shuttle 1994
Jaedong 1206
Hyuk 962
firebathero 743
Mini 638
BeSt 524
Horang2 513
Larva 211
[ Show more ]
Stork 211
Rush 204
ZerO 160
hero 133
Hyun 119
Last 118
Sharp 105
Pusan 99
ggaemo 95
JulyZerg 64
JYJ 56
Killer 49
Mong 49
Free 43
sorry 37
soO 36
Movie 29
Shine 27
Aegong 25
HiyA 23
ToSsGirL 17
Hm[arnc] 17
NaDa 14
yabsab 13
Barracks 12
IntoTheRainbow 9
Noble 9
ajuk12(nOOB) 8
Rock 7
Purpose 6
Icarus 5
Dota 2
Gorgc5704
XcaliburYe198
League of Legends
Doublelift3611
Counter-Strike
byalli1695
allub430
Heroes of the Storm
Khaldor136
Trikslyr14
Other Games
gofns20204
singsing1912
B2W.Neo814
RotterdaM196
Hui .136
XaKoH 127
DeMusliM126
ZerO(Twitch)13
BlysK5
Organizations
Other Games
gamesdonequick2306
BasetradeTV169
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• CranKy Ducklings SOOP79
• musti20045 18
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Pr0nogo 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 540
League of Legends
• Jankos3329
Upcoming Events
IPSL
2h 23m
Dragon vs Hawk
RSL Revival
19h 23m
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
20h 23m
OSC
23h 23m
IPSL
1d 2h
Bonyth vs Ret
WardiTV Weekly
1d 21h
Monday Night Weeklies
2 days
PiGosaur Cup
3 days
The PondCast
3 days
Replay Cast
4 days
[ Show More ]
CrankTV Team League
4 days
Replay Cast
5 days
CrankTV Team League
5 days
Korean StarCraft League
6 days
RSL Revival
6 days
Liquipedia Results

Completed

Escore Tournament S3: W3
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
YSL S3
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer 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 © 2026 TLnet. All Rights Reserved.