3 ms·
not a python dev, but: - python probably has a lib like underscore (reduce map filter etc), could help - check out the quake source code, any version, its hug
by mc_hammer 12y ago
not a python dev, but:
- python probably has a lib like underscore (reduce map filter etc), could help
- check out the quake source code, any version, its huge and the entire thing is not only readable but possibley a work of art.
- have you tried lambdas? to some its more readable.. ex:
nums = range(2,50)
for i in range(2, 8):
nums = filter(lambda x: x == i or x % i, nums)
personally when i have too complex process i like to go more functional, ex:
main:
prepare_data1()
prepare_data2()
do_long_stuff()
nextstep()
that allows me to focus on only on building one step and still have readable code.
many game-devs prefer breaking their project into many tiny files with a specific purpose instead of spaghetti, ex:
file.py
parser.py
display.py
function1.py
function2.py
its also a bit easier to nav around the project and make sense of it this way. you might want to check out rust or D or F or another lang also.
- TheLoneWolfling 12y agoPython has a built-in map. Reduce is in functools. Filter is in itertools. Between builtins, itertools, and functools, you pretty much have it covered.
- mc_hammer 12y agoThought so - python is a rly nice lang
- elliott34 12y agoExcuse my ignorance here: so are these functional programming paradigms?
- TheLoneWolfling 12y agoGenerally speaking, yes. (Look here: https://en.wikipedia.org/wiki/Higher-order_function#General_examples https://en.wikipedia.org/wiki/Higher-order_function#General_... )
- elliott34 12y agoDefinitely see what you're saying with the prepare_data1()...prepare_data(2). Maybe a more functional approach would be suitable. At the end of the day, data goes into a tunnel and comes out in a different form, into a machine learning model. So perhaps I should look at functional programming styles in python. Thanks!