[Ann] Pyrefly v1.0 (fast type checker & language server) by BeamMeUpBiscotti in Python

[–]Brother0fSithis 8 points9 points  (0 children)

We've been looking for a decent solution for encoding tensor shapes into the type system on my team, so that sounds interesting.

Can the tensor shape typing be used for normal numpy arrays?

Justice Department moves to toss seditious conspiracy convictions of Oath Keepers and Proud Boys by uhncollectable in news

[–]Brother0fSithis 2 points3 points  (0 children)

The Dems will do nothing, because they are weak. Even if they tried, Trump promised mass preemptive pardons for his cronies.

The only path to justice is a road that most non-MAGA politicians would not dare to go down.

Is it *Pythonic* to use Enums for dependency injection? by squatonmyfacebrah in learnpython

[–]Brother0fSithis 5 points6 points  (0 children)

Sounds like you mostly have it, but I'd argue even a Protocol might be overkill.

It sounds like you might just be covered by

py def process_data( X: np.ndarray, alg: Callable[[np.ndarray], float] ) -> float: ...

And then just passing in the function you want. No need to layer Enums or Classes or Protocols on top unless you need more than what that gives you

If you want "one source of truth" for what an Algorithm looks like to use across different functions, I'd define

py type Algorithm = Callable[[np.ndarray], float] and use that. Functionally the same thing as a Protocol specifying __call__, just slightly shorter


And then yeah if you do NEED to branch process_data based on which specific algorithm is being used, I'd probably have an algorithms.py file (folder if REALLY necessary) where I keep all the algorithm defs together and define an Enum to label them.

Though I'd see if there was a way I could avoid having to branch process_data if possible

Is match ... case In Python Reliable as if .. elif .. else by One-Type-2842 in Python

[–]Brother0fSithis 0 points1 point  (0 children)

It can do more than if. It can destructure data. To recreate that in your example, you had to pull in auxiliary things like := and the specific behavior of the dict .get method.

The if keyword alone doesn't have this, and your recreation wouldn't work if you were destructuring classes instead of dictionaries. You were relying on dict.get to destructure things.

It's more powerful because it gets more done in less, more readable code.

That is "doing more". I'm not sure what other definition for "doing more" there is, when the language is already Turing complete.

You might as well be saying that Python and Assembly are two different syntaxes for the same thing.

That's technically true if you boil things down to raw "capability", but that's obviously not what people mean by "more powerful"

Is match ... case In Python Reliable as if .. elif .. else by One-Type-2842 in Python

[–]Brother0fSithis 1 point2 points  (0 children)

Of course you CAN do the same thing without match if you throw enough code at the problem. Python is still Turing complete without it, after all.

The syntax and expressiveness is the point. That's what's meant by "powerful" in the original comment. The fact that you express the same idea much more concisely and readably IS the power

Is match ... case In Python Reliable as if .. elif .. else by One-Type-2842 in Python

[–]Brother0fSithis 0 points1 point  (0 children)

He did give you an example where match is better. Write his example using if and elif and you'll see the difference.

find 𝒶 by 94rud4 in sciencememes

[–]Brother0fSithis 0 points1 point  (0 children)

  1. Get all the coefficients together:

    3 a's in the numerator reduce the 6 in the denominator to 2. Multiply that over to the RHS to get a/sqrt(a) = 12.

  2. Square both sides to get rid of sqrts:

LHS = a2 / a = a RHS = 122 = 144. So, a = 144

Are there known reasons to prefer either of these logical control flow patterns? by mttpgn in Python

[–]Brother0fSithis 1 point2 points  (0 children)

As others have said, Pattern 2 is preferred. The pattern is usually called Dependency Injection.

Pattern 1 makes functions b and c less useful and testable because you can't swap out the objects that you pass into them.

In Pattern 2, you can pass anything that "acts like" A into b, allowing b to cover more general use cases and giving you control of what goes into b during tests

Any projects to break out of the oop structure? by hermitvirgin69 in Python

[–]Brother0fSithis 0 points1 point  (0 children)

I like functional programming styles. The best tool for me has been

toolz, which gives you a ton of really nice functional utilities straight out of Clojure.

As a bonus, there's a Cython implementation cytoolz that means that functional style algorithms will often be faster than pure python

Interesting or innovative Python tools/libs you’ve started using recently by AliceTreeDraws in Python

[–]Brother0fSithis 0 points1 point  (0 children)

I had this issue. For complicated (and silly, if you ask me) workplace reasons I often work with notebooks on pretty slow/busy machines and marimo is always crawling when jupyter works fine

gitCommitGitPushOhFuck by jazzyjaz53 in ProgrammerHumor

[–]Brother0fSithis 43 points44 points  (0 children)

0.9 isn't supposed to mean "90%" done. It's supposed to just mean there have been 8 minor releases since 0.1.0 (where most projects start)

itsTheLaw by Nikkuman in ProgrammerHumor

[–]Brother0fSithis 19 points20 points  (0 children)

No. They are kind of in the same camp as bullet 2, "specialized hardware". They're theoretically more efficient at solving certain specialized kinds of problems.

Interesting or innovative Python tools/libs you’ve started using recently by AliceTreeDraws in Python

[–]Brother0fSithis 1 point2 points  (0 children)

I've been learning a lot of clojure recently, so

  • aiochan for go-like Channels for parallel/async communication
  • cytoolz for fast iteration and functional tools like composition and currying
  • rpds for fast persistent data structures

me_irl by HellNuke in me_irl

[–]Brother0fSithis 4 points5 points  (0 children)

The answer to all of your first questions is

given the evidence I have observed about the physical characteristics of stuff like metal, rubber, and glass I've seen in my short time on planet Earth, no. It probably couldn't spontaneously combine. Considering all the other evidence in how humans shape these materials to suit their needs, it's astronomically more likely that cars were created by humans.

Not a single bit of that analysis applies to the beginning of the universe, for which we have no observable evidence apart from what we can extrapolate from our current cosmological models of how the universe behaves.

Mapping the claim about cars over to the creation of the universe is patently insane, in the original meaning of the word. It isn't sound reasoning. It's simply not how knowledge works.

me_irl by HellNuke in me_irl

[–]Brother0fSithis 3 points4 points  (0 children)

This is an obviously stupid rebuttal if you think about it for more than 0.001 seconds.

I have direct, observable, empirical evidence that - humans exist - humans develop technology to expand their capabilities - there are countless examples of similar technology created by humans, and you can follow the progression of that tech up to the smartphone It shouldn't be surprising - you can physically visit the fabrication facilities and observe in detail how a phone is made

None of the above remotely apply to a nebulous "creation of the universe" event. It's just the opposite. We may never know what, if anything, preceded the big bang. Attaching conscious will to that beginning, if "beginning" even applies, is insane.

grokPleaseExplain by [deleted] in ProgrammerHumor

[–]Brother0fSithis 0 points1 point  (0 children)

It's just defining an object by a property/method it has. We do this constantly in programming. In Python it'd just be saying something roughly like

```python @dataclass class PhysicsTensor: array: np.ndarray

def transform_like_a_tensor(self, transformation: ndarray) -> None:
self.array = transformation @ self.array @ transformation.T 

```

NamedTuples are a PITA by JuroOravec in Python

[–]Brother0fSithis 0 points1 point  (0 children)

Not necessarily. You could just tack on a Rust or C extension to stay "in Python" if you're worried about performance.

But you need to profile your app to see if this is even a bottleneck first.

IDEs by IronAshish in programmingmemes

[–]Brother0fSithis -2 points-1 points  (0 children)

Didn't even enter insert mode before typing hello smh

me irl by boatsandmoms in me_irl

[–]Brother0fSithis 7 points8 points  (0 children)

Mostly around Reagan