stevensanderson, to FunctionalProgramming
@stevensanderson@mstdn.social avatar

The map() function applies a function across vectors, lists, or data frames efficiently. Syntax: map(.x, .f, ...) where .x is data, .f is function, ... for extra args. Examples: square vector elements via ~.x^2, get means of column across list of data frames with ~mean(.x$y), apply custom functions to rows/cols like df$z <- map_dbl(df, add_cols).

#R

Post: https://www.spsanderson.com/steveondata/posts/2023-03-26/

image/png
image/png

GregCocks, to conservative
@GregCocks@techhub.social avatar

Shipwreck Ecology - Understanding The Function And Processes From Microbes To Megafauna

https://doi.org/10.1093/biosci/biad084 <-- shared paper

[as a scuba diver who has done some wreck diving in various places around the world, there is an extra layer of interest here for me…]

photos - examples - shipwreck habitats
maps - shipwrecks - globally
graphic - fundamental ecological functions and processes occurring on shipwrecks

treyhunner, to python
@treyhunner@mastodon.social avatar

Ever seen "lambda" in ?

That's a function.

But wait... aren't functions made with "def" statements? How are lambda functions different and why are they used?

That's the topic of this week's Python Morsels article.

https://pym.dev/lambda-expressions/

cazabon,

@treyhunner

It still pisses me off that complains if you ever bind a to a name. "Use a instead!" it whines.

Every time, I want to channel : "Leave me alone, I know what I'm doing!"

ado, to python

I am really excited for 3.12 for three reasons.

First reason - No more ugly TypeVar declarations.

Old generic type:

from typing import Generic, TypeVar<br></br><br></br>_T_co = TypeVar("_T_co", covariant=True, bound=str)<br></br><br></br>class ClassA(Generic[_T_co]):<br></br>    def method1(self) -> _T_co:<br></br>        ...<br></br>

New generic:

class ClassA[T: str]:<br></br>    def method1(self) -> T:<br></br>        ...<br></br>

Second reason: 🚀 Gotta go fast. From the abstract

Comprehensions are currently compiled as nested functions, which provides isolation of the comprehension’s iteration variable, but is inefficient at runtime. This PEP proposes to inline list, dictionary, and set comprehensions into the code where they are defined, and provide the expected isolation by pushing/popping clashing locals on the stack.

Last: F Strings will support some common use cases that broke interpolation in the past, like f'{ myDict['myKey'] }' and f"{'n'.join(a)}"

Full notes: https://www.python.org/downloads/release/python-3120b3/

cazabon,

@folkerschamel @ado

And yes, many of them are that would be to find by other routes. Your unit test doesn't try passing a to that you wrote that you only considered using ints with - but with hints, mypy will find that "one weird way" that a float value returned from somewhere else could get passed into the function.

Type hints in code - used well and consistently, no using "" to shut mypy up - make me 50% more productive, I think. </anecdote>

_alen, to python

At first, I didn’t like type hints in , but we decided to give it a go since our codebase really exploded in the last couple of years. All I can say now is we should have done it earlier. I still find it unbealivable that we discovered so many small bugs that went unnoticed all these years.

cazabon,

@folkerschamel @_alen

Static type do help find - even ones that would be nasty to try to debug after hitting them in use.

But you can also use them to enforce , if you prefer that to duck typing (not built-in). A lot of Pythonistas will hold their nose at that, but it can be useful to "die loudly and early" when someone else passes the wrong to your .

grumpygamer, (edited ) to random
@grumpygamer@mastodon.gamedev.place avatar

ok, now the most important part of game dev: variable naming.

demiurg,
@demiurg@fosstodon.org avatar

@grumpygamer Please, we all have read and inhaled PEP 8 🧐

https://peps.python.org/pep-0008/#function-and-variable-names

ramzesenok, to random
@ramzesenok@mastodon.social avatar

For quite some time I’ve been collecting some tips and tricks in and that I’d like to share with you. I’ll share a new tip every day and hope to last until at least WWDC

I'll also post same content on Twitter in case you prefer it over Mastodon

ramzesenok,
@ramzesenok@mastodon.social avatar
  • Day 17
    When debugging or testing, knowing where a function was called from can be crucial. Use , , and literals to get filename, line, and function name. These can be used in any function, and passed as default parameters to other functions
jimdonegan, to science
@jimdonegan@mastodon.scot avatar
  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • cubers
  • DreamBathrooms
  • InstantRegret
  • tacticalgear
  • magazineikmin
  • Youngstown
  • thenastyranch
  • mdbf
  • slotface
  • rosin
  • modclub
  • kavyap
  • ethstaker
  • provamag3
  • osvaldo12
  • khanakhh
  • cisconetworking
  • Durango
  • everett
  • ngwrru68w68
  • Leos
  • normalnudes
  • GTA5RPClips
  • tester
  • megavids
  • anitta
  • lostlight
  • All magazines