@folkerschamel@mastodon.social
@folkerschamel@mastodon.social avatar

folkerschamel

@folkerschamel@mastodon.social

I love creating new software.

"All problems of humanity cannot be solved by another level of inaction" - (what David John Wheeler really meant)

This profile is from a federated server and may be incomplete. Browse more on the original instance.

chrisphan, to Excel
@chrisphan@hachyderm.io avatar

I'm not a big fan, but it is widely used and many people are comfortable with it. Putting in there makes sense (as long as it's appropriately sandboxed, etc.).

folkerschamel,
@folkerschamel@mastodon.social avatar

@chrisphan

The code seems to be running in the cloud. So if there's a sandbox escape bug, then you can gain root rights of all applications worldwide running on .

nm, to internet
@nm@veganism.social avatar

Servers have been quiet about their plans to defederate from 's .

Only one major server's status has changed over the last two weeks, according to the stats on our tracker.

https://fedipact.veganism.social/

I wonder how much discussion there'll be once Meta enables their Activity Pub integration.

folkerschamel,
@folkerschamel@mastodon.social avatar

@nm

Seems to be no significant change in the statistics:

As before, about 90% of users are on servers who want to federate with or w/o info available about their stance on (technical default would be federating).

Two weeks ago: https://mastodon.social/@folkerschamel/110858085655817531

folkerschamel, to python
@folkerschamel@mastodon.social avatar

⁉️ Another for
!

What is the value of the following expression? Why?

sum(map(lambda q, x=[]: (x, x.append(1))[0], range(10)), [])

(Another riddle is https://mastodon.social/@folkerschamel/110876661322264891)

folkerschamel, to python
@folkerschamel@mastodon.social avatar

@ketmorco @zenforyen @diazona @bk1e @askonomm @cazabon @ado @kevin

This unsolved challenge bugs me:
How can I add type hints to the following class

class D:
def init(self, t):
self._t = t
def getattr(self, n):
def m(*args):
print("a")
getattr(self._t, n)(*args)
print("b")
return m

so that can detect type bugs like the following?

class Q:
def f(self, x: int):
print(x)
q = Q()
d = D(q)
d.f(2.0)

folkerschamel,
@folkerschamel@mastodon.social avatar

@orsinium @ketmorco @zenforyen @diazona @bk1e @askonomm @cazabon @ado @kevin

It seems that the case I describe is even harder, since both https://github.com/python/mypy/issues/5523 and https://github.com/python/mypy/issues/2087 seem to be only about proxies for accessing attributes, not methods, right?

What would be a dirty hack?

I can imagine (ugly) solutions by forcing the user to define an interface base class for Q and creating a factory function for D, as indicated in https://mastodon.social/@folkerschamel/110888560820113321 ...

folkerschamel,
@folkerschamel@mastodon.social avatar
folkerschamel,
@folkerschamel@mastodon.social avatar

@bk1e @orsinium @ketmorco @zenforyen @diazona @askonomm @cazabon @ado @kevin

You could define an interface class returned by the wrapper factory function. But it seems at some point you still have to lie about the type.

folkerschamel,
@folkerschamel@mastodon.social avatar

@bk1e @orsinium @ketmorco @zenforyen @diazona @askonomm @cazabon @ado @kevin

You mean at runtime or at static-type-check time?

moorejh, to twitter
@moorejh@mastodon.online avatar

Thousands of scientists are cutting back on Twitter, seeding angst and uncertainty https://www.nature.com/articles/d41586-023-02554-0

folkerschamel,
@folkerschamel@mastodon.social avatar

@moorejh

is open source information. So open source software and the open is a natural home for .

folkerschamel, to python
@folkerschamel@mastodon.social avatar

⁉️ time!

What is the result of the following Python expression?

Why?

[x for x in range(2, 1000) if all(range(x + 1)[::y][-1] != x for y in range(2, x))]

Enjoy!🙃

(Another riddle is https://mastodon.social/@folkerschamel/110867567641826240)

folkerschamel,
@folkerschamel@mastodon.social avatar

@tikhonov_a Isn't a crazy clown in all of us?😆

StatisticsGlobe, to python
@StatisticsGlobe@mastodon.social avatar

Quick Python Quiz - Converting String to Integer!

Can you explain this? How do you convert a string to an integer in Python?

video/mp4

folkerschamel,
@folkerschamel@mastodon.social avatar

@StatisticsGlobe

Converting a string into an integer? Any integer? No additional requirements?

Then you can use len(s).

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/

folkerschamel,
@folkerschamel@mastodon.social avatar

@cazabon @ado

Do you have representative specific samples of bugs you found that way? Trivial bugs or nasty bugs, dangerous skeletons in the closet? Could automated tests have caught them, too?

Did you consider switching from to statically typed languages like , or ?

There was a time when I couldn't imagine in the world to use a dynamically typed language for serious programming. I changed my view completely. B
May be the same with type hints. But maybe not.😉

folkerschamel,
@folkerschamel@mastodon.social avatar

@lukeshu @cazabon @ado

Doesn't testing include type issues and build confidence in your code even more?

folkerschamel,
@folkerschamel@mastodon.social avatar

@cazabon @ado

I remember recently learning about one case where some code intentionally mixing integer and float calculations was writing out the wrong type into Elastic Search, causing an inconvenience in Kibana visualizations because integers don't allow the same aggregation functions as floats.

But this is the only case I can remember static type checks probably would have caught, and it was quite harmess.

Maybe I miss something, or maybe our code base is just different, who knows.😉

folkerschamel,
@folkerschamel@mastodon.social avatar

@cazabon @ado

From the more theoretical perspective - knowing that this is definitely not an exhaustive perspective - right now I cannot imagine situations where a type bug wouldn't be also a functional bug, which would be caught anyway by code review or testing.

Mixing floats and integers comes closest. But also here I think does a good job avoiding mistakes. For example, the type of a result of all operations does depend only on the input types, but never on the input values.

folkerschamel,
@folkerschamel@mastodon.social avatar

@cazabon @ado

I just realize: As far as I understand , my previous Elastic Search example wouldn't be caught by because the parameter was passed to a logging function using formating via an f-string.

folkerschamel,
@folkerschamel@mastodon.social avatar

@tshirtman @cazabon @ado

Interesting.

Interestingly such cases are not caught by compilers of statically typed languages like or (assuming you are talking about situations where you would use pointers/references in /).

For our software we have the explicit coding style that functions must support None/null/null-pointer parameters for class instances (or more general, never expect conditions met). So maybe this convention helps us creating robust code for such cases.

folkerschamel,
@folkerschamel@mastodon.social avatar

@diazona @cazabon @ado

I see your first point theoretically. But I don't remember situations where I thought "static type checking would have helped us avoiding that trouble". But I keep it in mind.🙂

About documentation, I see the argument in theory. But I think in practice you get that information for free by naming (e.g. "counter" -> int, "name" -> str) or documentation ("number of elements" -> int, "object supporting xyz").

In general, specific real-world examples would be interesting.🙂

folkerschamel,
@folkerschamel@mastodon.social avatar

@DanielaKEngert @tshirtman @cazabon @ado

Interesting.

We have the opposite coding style:😉 a) Parameters and return values must not be references, but pointers, b) function must support null pointer parameters, and c) callers must support null pointer return values.

In our interfaces there are many situations where passing or returning "no object" is quite useful. So to keep it simple and reduce null pointer exception risks, we make it a rule to always support it.

folkerschamel,
@folkerschamel@mastodon.social avatar

@DanielaKEngert @tshirtman @cazabon @ado

Interestingly it's related to fault-tolerant code.

For example, a function find_some_object (loading a resource) may not find the object, report an error, return null.
The caller should continue, possibly passing that null pointer to other functions without raising an exception or even aborting.

folkerschamel,
@folkerschamel@mastodon.social avatar

@tshirtman @DanielaKEngert @cazabon @ado

I fullly agree that you should avoid relying on human behavior. Automation is much more powerful. Also, frankly, our automated testing is not as comprehensive as it should be (historical and practical reasons). But in practice at least I don't remember cases where static type checking in would have saved us trouble.

Duplication: Yes, our code is full of null pointer/None checks. You see tons of if(obj) / if obj: statements.😉

folkerschamel,
@folkerschamel@mastodon.social avatar

@tshirtman @DanielaKEngert @cazabon @ado

In references are the way of disallowing null pointers:

void f(X *x)

versus

void f(X &x)

folkerschamel,
@folkerschamel@mastodon.social avatar

@danjac @cazabon @ado

Completely agree.

Even more in general:
When working on an existing code base, you following the architecture and coding styles of that project.

  1. Because people before you have put thoughts into that.
  2. To maintain a consistent architecture and coding style.

But if you start implementing a new micro service, you can choose again.🙂

Edent, to random
@Edent@mastodon.social avatar

All other things being equal, which of these coding conventions do you prefer?

property(object) or object.property() ?

For example, length($things) or $things.length()

What about if you are manipulating the object? E.g. upperCase($text) or $text.upperCase()

(Not doing a poll because I'd prefer a discussion.)

folkerschamel,
@folkerschamel@mastodon.social avatar

@Edent obj.something() to not pollute the global namespace.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • megavids
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • provamag3
  • tester
  • Leos
  • JUstTest
  • All magazines