Script47 Posted September 23, 2014 Share Posted September 23, 2014 Which one and why? Quote Link to comment Share on other sites More sharing options...
G7470 Posted September 23, 2014 Share Posted September 23, 2014 Personally, it all depends. A lot of the code I write is not for a completely blank website or a blank application. Most of the time, it's adding onto it or fixing problems with said application. So in those cases, my coding convention mimics what is already there in order to keep the coding bases somewhat consistent. If it is a blank website or my personal site, most of my variables do not even have either of these conventions. A lot of times I make my variables all one word, all lowercase with comments around it explaining what the variable is and what it is used for. ~G7470 Quote Link to comment Share on other sites More sharing options...
Djkanna Posted September 23, 2014 Share Posted September 23, 2014 Both; Depends usually on the convention adopted by existing code/framework etc. Quote Link to comment Share on other sites More sharing options...
SRB Posted September 23, 2014 Share Posted September 23, 2014 Work: underscore. Personal: camelCase Freelance: adopt what's already in use Quote Link to comment Share on other sites More sharing options...
sniko Posted September 23, 2014 Share Posted September 23, 2014 camelCase is really nice snake_case is horrible I adopt a spin of the Hungarian notation, and camelCase "feels/looks" better. For example; $str_user_name = "foo"; $strUserName = "foo"; Quote Link to comment Share on other sites More sharing options...
Script47 Posted September 23, 2014 Author Share Posted September 23, 2014 If it is a blank website or my personal site, most of my variables do not even have either of these conventions. A lot of times I make my variables all one word, all lowercase with comments around it explaining what the variable is and what it is used for. ~G7470 I've personally felt that when you have a variable in one long line it is a lot harder to read. Could you show snippets of some of you code if you could please? Quote Link to comment Share on other sites More sharing options...
G7470 Posted September 23, 2014 Share Posted September 23, 2014 Of course with a name too long, it could greatly effect the readability; however, you can also make the variable names relative to its purpose to improve this issue. Here's a little snippet from a drug modification mod that I made: $growdrugres = mysql_query("/* QUERY HERE - LEFT OUT FOR SNIPPET */"); if(mysql_num_rows($growdrugres) > 0) { while($drugarr = mysql_fetch_array($growdrugres)) { if($drugarr['ending'] < time()) { $countdrug = 1; } } if($countdrug == 1) { echo "<center><a href='growdrugs.php'><b>Click here to harvest your drugs.</b></a></center>"; } } One more, probably the longest variable names I have ever made here from another mod I made: $drivebyconfig = mysql_query("/* QUERY HERE - LEFT OUT FOR SNIPPET */"); $drivebyconfigsettings = mysql_fetch_row($drivebyconfig); $requiredwep = $drivebyconfigsettings[0]; $requiredarm = $drivebyconfigsettings[1]; $requiredcar = $drivebyconfigsettings[2]; ~G7470 Quote Link to comment Share on other sites More sharing options...
sniko Posted September 23, 2014 Share Posted September 23, 2014 Of course with a name too long, it could greatly effect the readability; however, you can also make the variable names relative to its purpose to improve this issue. Here's a little snippet from a drug modification mod that I made: $growdrugres = mysql_query("/* QUERY HERE - LEFT OUT FOR SNIPPET */"); if(mysql_num_rows($growdrugres) > 0) { while($drugarr = mysql_fetch_array($growdrugres)) { if($drugarr['ending'] < time()) { $countdrug = 1; } } if($countdrug == 1) { echo "<center><a href='growdrugs.php'><b>Click here to harvest your drugs.</b></a></center>"; } } One more, probably the longest variable names I have ever made here from another mod I made: $drivebyconfig = mysql_query("/* QUERY HERE - LEFT OUT FOR SNIPPET */"); $drivebyconfigsettings = mysql_fetch_row($drivebyconfig); $requiredwep = $drivebyconfigsettings[0]; $requiredarm = $drivebyconfigsettings[1]; $requiredcar = $drivebyconfigsettings[2]; ~G7470 Wow, that's so '07 :p Quote Link to comment Share on other sites More sharing options...
G7470 Posted September 23, 2014 Share Posted September 23, 2014 Wow, that's so '07 :p Oh, sniko the critic I see. :p ~G7470 Quote Link to comment Share on other sites More sharing options...
Sim Posted September 25, 2014 Share Posted September 25, 2014 Freelance: adopt what's already in use Same.. Personal: underscore for variables and CamelCase for functions and methods Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.