Have you thought about casing? - stitcher.io
source link: https://www.stitcher.io/blog/have-you-thought-about-casing
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Scout APM helps PHP developers pinpoint N+1 queries, memory leaks & more so you can troubleshoot fast & get back to coding faster. Start your free 14-day trial today.
« back — written by Brent on December 20, 2018
Have you thought about casing?
SUBTRACT data-item-1 FROM data-item-2
userId
user_id
I'VeMadeTheArgumentManyTimesBefore:ProgrammersShouldn'TUnderestimateTheValueOfCodeReadability.TodayI'LlArgueOnceMoreAgainstACommonPracticeWeAllSeemToTakeForGranted:Casing.
ItSeemsLikeSuchAMinorDetail,Right?UsingCamelsOrSnakesOrKebabsToStringWordsTogether,WhoCares?There'SMoreToThisQuestionThough.
CodeReadabilityShouldn'TBeNeglected.ItImpactsHowEasyYouCanNavigateAndUnderstandYourCode.WeShouldTalkAboutTheCasingConventionsWeUse.
EarlyProgrammingLanguagesDidn'THaveTheSameConventionsWeHaveToday.LanguagesLikeLispAndCOBOLOriginatedBeforeWidespreadASCIISupport,ExplainingTheDifference.Upper-AndLowerCase,AndSpecialCharactersLikeUnderscoresSimplyWeren'TSupportedByCompilersBackInThe50sAndEarly60s.
BothLispAndCOBOLAllowedForHyphensToSplitWords.Lisp'SParserWasSmartEnoughToDetectWhetherAHyphenWasBetweenTwoWords,OrWhetherItShouldBeUsedAsTheSubtractionOperator.COBOLOnlyHasFullWordsAsOperators,EliminatingTheProblemAlltogether.Here'SASubtractionInCOBOL:
BecauseTheHyphenIsn'TAReservedKeyword,ItCanBeUsedToSplitWords.
WhenProgrammingLanguagesMaturedInThe80sAnd90s,ItBecameClearThatTheHyphenShouldBeReservedForMathematicalOperations.AnotherIssueWithLisp'SSmartApproachWasThatItDidn'TScaleInModernLanguages,ItSlowedDownTokenisationSignificantly.
SpacesObviouslyCouldNeverBeUsed,AsAlmostEveryProgrammingLanguageUsesThemAsTheBoundaryBetweenTokens.SoWhat'SLeft?HowCouldWeWriteMultipleWordsAsOne,WhileKeepingTheseWordsReadable?
ThisIsWhyWe'ReLeftWithTwoMajorConventionsToday:CamelCase,EitherLower-OrUpper;AndSnakeCase.AsASidenote:UpperCamelCaseIsAlsoCalledPascalCase.
MostOfTheTime,ALanguageTendsToFavouriteOneOfTheTwoCasings.WeCouldSayIt'SAMatterOfCommunityGuidelines,AndBeDoneWithIt.
It'SMyOpinionThatThere'SMoreToIt.ThereIsOneBetter,MoreReadableWayOfWritingWords.YouCanProbablyGuessWhichOne,BasedOnTheStartOfThisBlogPost.CamelCaseMakesTextMoreDifficultToRead,ComparedToSnakeCase.
GivenTheWordUserId,CompareTheTwoWaysOfWritingIt:
It'STrue:CamelCaseIsMoreCompact:YouDon'THaveToWriteAsMuch.ButWhichStyleIsTheClosestToHowTheHumanBrainActuallyReadsAText?
ThisIsTheOnlyArgumentThatMattersToMeInThisDiscussion:
ReadableCode,ReducesCognitiveLoad.LessCognitiveLoadMeansMoreMemorySpaceForHumansToThinkAboutOtherThings,ThingsLikeWritingBusinessLogic.
"AllOfThatJustByUsingUnderscores?"No,NotJustBecauseOfUnderscores.There'SMuchMoreToWritingReadableCodeThanNamingConventions.ButAllSmallThingsHelpInGettingABiggerSolution.
Follow me: Twitter — RSS — Newsletter — Patreon — GitHub
© 2020 stitcher.io — Cookies & Privacy
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK