Usecase for Tuples?
Skipping defining a struct. If you have an editor and toolchain that aren't shit garbage you should be able to automatically replace a tuple with an identically implemented struct.
>>106823537none
>>106823567>Skipping defining a struct.sounds pretty based senpai desu ngl
libraries with functions that take tuples as arguments for some reason
>>106823630Kek
They're for lazy undisciplined
>>106823537Saves you from declaring before assigning the result of a function of there's many results.Can live without it.But it is nice that the outputs are separated.
>>106823537element ordering memorization exercise for longevity purpose
TULPAS?
>>106824468Oh yeah. Tuples are best utilized in a top-down memoization context.Cue the classic Factorial memoization algo.
I think my last post was not submitted.Read this book on type theory:https://github.com/Chubek/chubek/blob/master/type-theory-intro.pdf
Also, `wget(1)` this book I generated with Opus 4.1. I fed it loads of books on type theory and got this book. Read it with QuteBrowser.https://gist.github.com/Chubek/210ba1f14e585a371a4223cf10d3b30bIt also talks about type theory in context of Simply-typed Lamda Calc, Category Theory, and Combinatory Logic.Even though I fed it books and papers, it's still LLM-generated. So be vigilant.
>>106824494meep?
>>106824544Tuples can be used as product types.They are structurally immutable, but they are element-wise assignable.That's why they are great for memoization.
>>106823537Assuming we're talking about polycules, consider this: a polycule may eventually come to have none of its original members. Theseus' polycule, if you will. Curious.
>>106823537Tuples are like a "frozen" array. It cannot grow larger or smaller, its just a fixed multi-value object.if your function needs to return more than one value, tuples are one option, if you don't want to bother with creating a structure or a class
>>106824605and forgot to mention, imagine you need a dictionary/map and the key of such thing is more than one value.Imagine you have like a shirt inventory, and you want to get the shirts that are (Red,Large) and you already have that as a key in a dictionary.shirts1 = shirtCollection[(Red,Large])
>>106824631Yeah tuples are hashable by default. That's because they only contain a reference to the underlying objects inside them. They are like 'frozen sets'.I have to add tuples to my language Diyrbal. I do have AGDts, but 'imperative' tuples are also useful.
>>106823537- Immutability makes them ideal for transporting data during inter-process communications and async operations- Immutability makes them hashable, so you can jam ordered data into keys of a big hashtable if you want (this is one solution to the anagram detection problem)- Immutability also makes them excellent rows for matrices or read off of an iterator pulling from a DB
Python has, not to be mistaken with the 'OOP' concept of objects, and all Python objects, including the class object, are constructed from this 'proto-object', by defining several 'protocols' (e.g. numeric, callable, iterable, etc).Tuples are defined using this 'proto-object'. So are lists, so are 'types', which manifest in syntactic sugar as classes.https://cs.brown.edu/research/plt/dl/lambda-py/lambda-py.pdf
>>106824631Imagine having sex
>>106824577
>>106824988> hint hint, nudge nudgehttps://www.youtube.com/watch?v=4Kwh3R0YjuQTo add to my virginity, 'Python' in 'Monty Python' does not refer to the snekk. It is a made-up word, which in quite the Python-esque manner, is pronounced with a Schwa instead of a Long A.Idiots here still call Python with an 'o' as in 'door'.
>>106823537Unless you can make named tuples I tend to go with a struct or a class cause it's just easier to read.
>>106825018Somebody post it..
>>106825053In C++ I usually just document the tuple members being returned in a doc comment. Often a pair of values, the expected result and whether or not an error occurred.
>>106825053Depending on the semantics, and how much Zero-cost abstraction is guaranteed by the languages, data structures are fine. They are another form of product types, after all.However, choosing a class does not guarantee ZCA. Because of the vtable, and dynamic dispatch.Some languages, interpreted or compiled, are smart enough to optimize out the vtable when there's no need for dynamic dispatch, treating the class as an struct. DMD and GDC for D are like that (LDC is not). But interpreted languages don't care. If you use a class for a product type, you are adding overhead.If you want named tuples, must languages, including the aformentioned D, provide them via metaprogramming. Python's only mode of metaprogramming is metaclasses, achieved mostly through decorators. If you use a `@dataclass` decorator, Python treats the class as a product type, and factors out vtable and dynamic dispatch.
Also, be wary of CoW semantics (Copy-on-Write) which some languages impose on tuples.
>>106823537some king of optimization for modern BASIC clones
>>106825100I've just been working with python lately and I'm not even gonna bother with such performance considerations, just readability, because the lack of a proper type system makes it all a bunch of error prone garbage code anyway. Good enough for some proof of concept backend web server.I miss doing low level graphics programming in C++ and focusing on maximum performance optimizations.
>>106823537Bad names are worse than no names. If there really is no neaningful label to describe a collection of values, introducing a meaningless AWithB struct is worse than just using a built-in (A, B) tupleBeing able to construct a type metaprogramically. For example you have some operation that takes some argument. Then you have a bunch of mixins that extend that operation, but some of them require an extra argument. Rather than having the argument be dynamic that then has to be checked for validity each operation at runtime, you can create a static superargument tuple that is known at compile to hold argument data for all the mixins
>>106825174We call atomic features of a language "constructs". Also, according to Rice's theorem, no construct could be an optimization on its own.>>106825195Python is a sweet language for prototyping. If you make webservers, know that AsyncIO library has a ready-made mini-http server.I've personally haven't touched Python for 2 years. I already have enough Python projects, and it gives me no joy, and it's bit of a normie yokel unwashed masses proletariat language so I stay away from it.The only use I had for Python was string processig, until I found out Awk could do it much faster, and better. We're 2 years away from UNESCO declaring people who don't know Python are illiterate.
What annoys me about CPython (not other implementations) is that it builds a CFG, so it could easily collect traces and add a Tracing JIT.But that motherfucker Guido (what a shitty name) does not want any form of JIT. I realize there are libraries that leverage the CFG to add JIT via decroators, but why not make it builtin?PyPy outperforms CPython by a factor of 4 in most clases. It has meta-tracing JIT.And we have Nuitka, which just compiles Python to C.All these yummy, fast snekks, and everyone just uses the worst implementation.It's like, people using TinyC instead of GCC.
>>106823537Idk, libraries wants them. I just use dicts
Lua 5 tables are amazing.They are made up of an array part, and a hashmap part. When you index it, given the subscriot is an integer of 1...+inf, it looks forward to see if index/2 has been allocated, and the range is not sparse. If it is, it makes the number a hashmap index. Otherwise, an array index.All languages need something like this. Especially Python.
TinyC is a memory save language