loading...
Cover image for What Did You Learn This Week --April 24?

What Did You Learn This Week --April 24?

waylonwalker profile image Waylon Walker ・1 min read

this-week-i-learned (13 Part Series)

1) What Did you Learn this week --March 6? 2) What Did you Learn this week --March 13? 3 ... 11 3) What Did you Learn this week --March 20? 4) What Did You Learn This Week --March 27? 5) What Did You Learn This Week --April 3? 6) What Did You Learn This Week --April 10? 7) What Did You Learn This Week --April 17? 8) What Did You Learn This Week --April 24? 9) What Did You Learn This Week --May 1? 10) What Did You Learn This Week --May 8? 11) What Did You Learn This Week --May 15? 12) What Did You Learn This Week --May 22? 13) What Did You Learn This Week --May 29?

Discussion

markdown guide
 

This week was a productive one!

  • I improved last week TypeScript unit testing
  • Created particles emitters

  • Learnt about Spatial Hash Maps to improve performances of particles (w/ help of another contributor)
  • Fixed the collision system that was just random, now it has math 🤣

  • Created particles absorbers (black holes)

  • A lot of refactoring and bug fixing, but it's not much exciting 🤣
 

Those particles are amazing.

 

This week I learned about binding default values to dynamically created lambdas in python.

## WRONG 💥
files = ['abc', 'def', 'ghi', 'jkl']
funcs = []
for file in files:
   funcs.append(lambda: print(file))
funcs[0]()

😲 This prints 'jkl'. in fact every function prints 'jkl', they just print the latest value of 'jkl'

## CORRECT 🎉
files = ['abc', 'def', 'ghi', 'jkl']
funcs = []
for file in files:
   funcs.append(lambda x=file: print(x))
funcs[0]()

Now this is more of what I was looking for. The value of file was bound to the lambda upon creation, and will print out each value of the list as intended... Hard lesson learned this week.