[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


🎉 Happy Birthday 4chan! 🎉


[Advertise on 4chan]


File: Untitled.png (6 KB, 442x134)
6 KB
6 KB PNG
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.
>>
>>106823537
none
>>
>>106823567
>Skipping defining a struct.
sounds pretty based senpai desu ngl
>>
libraries with functions that take tuples as arguments for some reason
>>
>>106823630
Kek
>>
They're for lazy undisciplined
>>
>>106823537
Saves 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.
>>
>>106823537
element ordering memorization exercise for longevity purpose
>>
File: Mermaid_Man_stock_art.png (249 KB, 1500x1500)
249 KB
249 KB PNG
TULPAS?
>>
>>106824468
Oh 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/210ba1f14e585a371a4223cf10d3b30b


It 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.
>>
>>106824494
meep?
>>
>>106824544

Tuples can be used as product types.

They are structurally immutable, but they are element-wise assignable.

That's why they are great for memoization.
>>
File: 1734484413495206.jpg (75 KB, 770x600)
75 KB
75 KB JPG
>>106823537
Assuming 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.
>>
>>106823537
Tuples 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
>>
>>106824605
and 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])
>>
>>106824631
Yeah 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
>>
>>106824631
Imagine having sex
>>
>>106824577
>>
>>106824988
> hint hint, nudge nudge

https://www.youtube.com/watch?v=4Kwh3R0YjuQ

To 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'.
>>
>>106823537
Unless you can make named tuples I tend to go with a struct or a class cause it's just easier to read.
>>
>>106825018
Somebody post it..
>>
>>106825053
In 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.
>>
>>106825053
Depending 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.
>>
>>106823537
some king of optimization for modern BASIC clones
>>
>>106825100
I'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.
>>
>>106823537
Bad 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) tuple

Being 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
>>
>>106825174
We call atomic features of a language "constructs". Also, according to Rice's theorem, no construct could be an optimization on its own.

>>106825195
Python 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.
>>
>>106823537
Idk, 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.
>>
File: mgeim.jpg (6 KB, 189x176)
6 KB
6 KB JPG
TinyC is a memory save language



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.