|
Hi All,
Can I ask what the definition of a Tuple is, a Python expert was going on aabout them being able to group a float, an integer & a string into an 'array' & being able to search them, to which I was asked how would you do that inn C, I answer a structure in an array. The I saw something about them coming to .NET...
|
|
|
|
|
A n-uple is an ordered atomic indivisible set of data. So yes, a structure is a n-uple. Tuples are simply 2-pieces n-uples, std::pair for example provides tuples.
ADD: one practical usage of tuples would be simple comparison and search between collections. Instead of having to overload an operator like in C++, creating a comparison methond in the structure like less guru-like C++ (which I prefer), creating a function to compare a structure instance to another or a macro like in C you simply can use the "==" provided by the language. Safer, more intuitive and faster to implement at the cost of raw power.
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
AFAIK, what you call n-uple is actually a tuple.
|
|
|
|
|
And you're perfectly right. I recalled my teacher lesson, who apparently got it wrong - wikipedia docet.
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
Tuples[^] have been available for a while in .NET. I assume you're referring to them coming as a return type in C#7[^].
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: have been available for a while in .NET.
Glad someone mentioned this.
|
|
|
|
|
Something I have been wishing I had since C# 1. I knew long before .NET what a tuple was in the context of set or relational theory, but ever so early in my C# days, I knew I wanted functions (methods) to be able to return multiple values, like the C# 7 tuple, not like an array, or some other Enumerable.
Do what thou wilt shall be the whole of the Law. - Liber AL vel Legis 1:40, Aleister Crowley
|
|
|
|
|
Technically you always could with a custom class. But, that's a pain.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
While it's been possible to return a Tuple from .NET since version 4, the syntax at the receiving end is rather cumbersome. This is why the new Tuple return type is so welcome. There's no more trying to figure out what the mysterious Item1, Item2 and so on are.
This space for rent
|
|
|
|
|
Yes, it's always annoyed the crap out of me to write a class just for multiple return values.
Do what thou wilt shall be the whole of the Law. - Liber AL vel Legis 1:40, Aleister Crowley
|
|
|
|
|
They are small plastic containers in which you can put leftovers for keeping them sealed in the fridge.
|
|
|
|
|
Ah, the famous Tupleware! It keeps the fridge organized. Just remember to manually execute the garbage collection after a while
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
Exactly. I bet there will be web2.0 tupperwares in a few years, that could communicate with your fridge.
|
|
|
|
|
If you don't remove the leftovers for a few years they would have established some pimitive form of government, like democracy.
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
And then, they would establish voting in the Lounge.
|
|
|
|
|
It's like a struct without defining it. It's useful because you can avoid having to make up names for things
|
|
|
|
|
Uhm, if there is a collection of data passed around it better should have a name, at least to mark its purpose. Being able to create unnamed objects at will means lowering the expected amount of design involved in writing solutions.
Unnamed entities (may them be structures or functions or whatever) may be a very good instrument but like a plasma torch they shouldn't be used carelessly...
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
harold aptroot wrote: you can avoid having to make up names for things Exactly why I regretted using one about five minutes after I used one
It's also my biggest problem with functional languages, what the hell do you have in your tuples!? (int, int) isn't telling me much...
The only time a tuple did me any good was when my boss made fun of me for not having a formal education in IT.
He said something, I asked him "what's that?", and he was all like "haha, yeah you didn't get that in school, of course."
I was their top programmer at the time, and I think that bothered him as, indeed, unlike my coworkers I didn't have formal education.
So anyway, I did some Open University courses and I read about tuples.
In a next conversation with my boss I told him "it's just some tuple" and then he asked me "what's that?"... THAT'S PAYBACK TIME BIATCH!!!
|
|
|
|
|
Tuples are pointless in their current implementation. The size limit is completely arbitrary, and the work around for the size limit is absurd. You'd be better off with a static class that contains a List<object> property. At least that way, you could populate it with a virtually unlimited number of data items, of any type.
Of course, it doesn't have to be static, so if you want persistence, or a unique ObjTuple for given situations, it's easy to code it as needed. I provided the IsString methods to illustrate type-checking that you might want/need. It could be expanded to include all intrinsic types.
public static class ObjTuple
{
public static List<object> Objects { get; set; }
<pre>
public static void Create(params object[] parameters)
{
ObjTuple.Objects = (ObjTuple.Objects == null) ? new List<object>() : ObjTuple.Objects;
ObjTuple.Objects.Clear();
ObjTuple.Objects.AddRange(parameters);
}
private static bool InRange(int index)
{
return (index >= 0 && index < ObjTuple.Objects.Count);
}
public static bool IsString(int index)
{
return (ObjTuple.InRange(index) && ObjTuple.IsString(ObjTuple.Objects[index]));
}
public static bool IsString(object obj)
{
return (obj is string);
}
}</pre>
Usage would be something like this:
ObjTuple.Create("Test", 1, 5.1);
foreach(object obj in ObjTuple.Objects)
{
if (ObjTuple.IsString(obj))
{
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 26-Aug-16 7:58am.
|
|
|
|
|
Let's just hope you never have two threads trying to use that class at the same time.
And that you never need to call two methods that use it (or one method in a loop) and use the return value of both in the calling method.
And don't even think about using it in ASP.NET!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: And don't even think about using it in ASP.NET!
Everything you listed can be easily addressed, except ASP.NET. Nothing can fix that, because it's a web technology.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Angular 2 seems set to fix it, based on my recent self-tuition in that framework and the TypeScript language, which it is written in.
Do what thou wilt shall be the whole of the Law. - Liber AL vel Legis 1:40, Aleister Crowley
|
|
|
|
|
Seems a bit of overkill when you could just return List<object>. But hey that's just me.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
A typed list, how pretensious, even if the type is object . In my appy days we used ArrayList .
Do what thou wilt shall be the whole of the Law. - Liber AL vel Legis 1:40, Aleister Crowley
|
|
|
|
|
LOL. Yessss, yessss, My Pretentious....
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|