-
Notifications
You must be signed in to change notification settings - Fork 0
Code Guide
Ivan Rudik edited this page May 7, 2019
·
10 revisions
The primary goal of your coding style should be clarity. We want other people and your future self to be able to easily understand what you wrote.
LJ Ristovska wrote a nice language-agnostic programming guide.
- Stata
- We generally should follow the Gentzkow and Shapiro Stata style guide, with the following exceptions:
- We do not use their
save_data
ormmerge
commands.
- Julia
- We follow the JuliaPraxis style guide and QuantEcon style guide.
- Variable names should be lowercase:
- π county_fips
- β County_FIPS, CountyFIPS, CountyFips, countyFIPS
- Variable names should be descriptive:
- π state_fips, gas_flare_rate
- β sfps, gf_rate
- Variable names should be underscore separated unless they are short and it is clear:
- π unemployment_rate_over_65, aqilevel, aqi_level
- β unemploymentrateover65
- Prefer clarity to brevity
- π state_fips
- β s_fips
- Prefer specificity to generality
- π nightlights_luminosity
- β nightlights
- Be consistent
- π county_fips, state_fips
- β county_fips, fips_state
- Function and program names should be verbs describing what they do
- π clean_birds
- β bird_cleaning, bird_cleaner
- Function names should be lowercase:
- π clean_birds_data
- β CleanBirdsData, Clean_Birds_Data, cleanBirdsData
- Function names should be underscore separated unless they are short and it is clear:
- π analyze_nightlights_birds, cleanbirds
- β analyze_nightlights_birds
- Prefer clarity to brevity
- π clean_birds
- β cln_brds
- Prefer specificity to generality
- π analyze_nightlights_birds
- β analyze_data
- Be consistent
- π clean_nightlights_data, clean_birds_data
- β clean_data_birds, clean_nightlights_data
-
Use one space before and after a single binary operator or a comparator.
- π
this + that
,this | that
,a >= 0
- β
this +that
,this|that
,a>=0
- Spacing around
^
,/
, or*
is optional.
- π
-
Use a space after a comma
- π run_regressions(data, fixed_effects)
- β run_regressions(data,fixed_effects)
-
Do not use a space after a unary operator or
%
when used to force a type.- π
negative_id = -id
- β
negative_id = - id
- π
-
If you are going to align vertically, prefer to align on the
=
. -
If the left-hand-side name lengths vary greatly in subgroups, align subgroups on the
=
. -
Prefer to split a long line after
=
,,
,||
,&&
. or(
.
-
Project Management
-
Style Guides