Skip to content

Instantly share code, notes, and snippets.

@khaotik
Last active July 31, 2017 03:04
Show Gist options
  • Save khaotik/9fc0856eab3ed7dec8524cda3fc5d96b to your computer and use it in GitHub Desktop.
Save khaotik/9fc0856eab3ed7dec8524cda3fc5d96b to your computer and use it in GitHub Desktop.
Collections of my python coding style
Collections of my python coding style
[General]
- Rules are recommended but not strict, and not recommnaded for code golfing.
- Name global constant like C macros, FOR_EXAMPLE
- Name global variable (non-constant) with prefix "g_"
- function arguments names always with suffix "_", to avoid clashes like fn( .., dtype=dtype ), it's weird and sometime cause misunderstanding of code
def example_function(arg1_, arg2_):
local1 = arg1_+arg2_
return local1
- never use @property, sometimes it cause trouble
[Symbolic](in tensorflow, theano etc)
- symbolic variable using prefix "s_"(theano TensorType, tensorflow placeholder ...)
- numeric variable (theano shared variable) using prefix "v_"
- sparse variable use prefix "S_", dense variable use "D_" or no prefix
- combine above rules together, for example:
vS_: sparse numeric variable
sD_: symbolic dense variable
- symbolic OPs(take symbolics as inputs/outputs), use prefix "op_"
- compiled function with numeric input, use prefix "fn_"
- types using prefix "t_", as opposed to C convention using suffix "_t"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment