|
are you using industrial tin-foil ? the household stuff won't work.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I always use industrial tin foil - it's twice as thick as the domestic version, and a lot cheaper if you buy it in 90m rolls.
Plus, your tinfoil hat can be extended with a tinfoil cape to cover your whole spine wioth little extra effort.
Just don't drop it ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
@OriginalGriff
the tin-foil cape is very soignee, butt the problem is: when you bend over, you can leave a butt-print in the cape which could be picked up by scanners.
very few people can make a perfect ass of themselves.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
C#: Which do you prefer (given the small number of array items):
Type stringType = typeof(string);
Type[] expectedTypes = Enumerable.Repeat(stringType, 3).ToArray(); or:
Type stringType = typeof(string);
Type[] expectedTypes = new Type[] {stringType, stringType, stringType}; or: (using an extension method):
Type[] expectedTypes = typeof(string).Repeat(3); Definition of the extension method:
public static T[] Repeat<T>(this T item, int n)
{
return Enumerable.Repeat(item, n).ToArray();
}
I'm curious if anyone has any strong preference, and why.
From my perspective, the first version is sort of silly but cute, given there's only 3 items being initialized. The second version, ok, but I don't like it because I hate repeating myself. The third version I really like as it's very readable but some people object to creating extension methods (not that I care, it's my code, haha.)
|
|
|
|
|
Type[] expectedTypes = new Type[] {typeof(string), typeof(string), typeof(string)}; I have a 'mild' preference for the above line.
|
|
|
|
|
My thought as well.
Software Zen: delete this;
|
|
|
|
|
Great minds...
|
|
|
|
|
Oh yuck, none of those. ToArray and anything from Linq is a cry for help.
|
|
|
|
|
PIEBALDconsult wrote: ToArray and anything from Linq is a cry for help.
hehe. This is the use case:
method = type.GetMethod("SomeMethodName", expectedTypes);
|
|
|
|
|
|
|
I prefer the 2nd method using C# intrinsic initializers.
I find that trivial wrapping in most cases tends to obscure, rather than clarify.
Also I don't need to know linq to understand it, so that's a bonus.
Real programmers use butterflies
|
|
|
|
|
Quote: but is not for programming questions. Oh wait, nevermind, you have been here awhile so it's allowed.
And to answer your question, I have no preference.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
ZurdoDev wrote: Oh wait, nevermind, you have been here awhile so it's allowed.
Well its not really a programming question. If you wander across the tracks to SO you will see questions like this (asking opinions on something) are almost always closed as not relevant.
Now - I don't want to use SO as a guideline for CP but in this case...
ZurdoDev wrote: you have been here awhile
So he knows that some very good developers will answer the question here instead of being inundated by newbie responses in the C# forum!
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
DRHuff wrote: Well its not really a programming question. ... (asking opinions on something) I was going to answer him with something like that (I totally agree with you) but then I thought... not worthy to start with
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
modified 24-Feb-20 11:33am.
|
|
|
|
|
DRHuff wrote: Well its not really a programming question. The title of his own message disagrees with you.
And I don't disagree with you. But I have seen newbie posters ask the same exact type of question and get flamed for it. Just making a point that most everyone will ignore.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
DRHuff wrote: being inundated by newbie responses in the C# forum! That is going to piss off Richard and Richard, those 2 answer the bilk of c# questions, calling them newbies should ge right up their noses.
Seriously the forums see very little idiocy, that seems to be limited to Q&A.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Mycroft Holmes wrote: Richard and Richard,
Wait - there are a couple of Dicks answering questions in the forum?
Mycroft Holmes wrote: Seriously the forums see very little idiocy, that seems to be limited to Q&A.
Shows you how much time I spend there...
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
I do have a small issue with your extension method.
It returns an array instead of an IEnumerable like everything else in LINQ.
That means it's directly evaluated even though you may not expect it (the original Repeat function isn't).
I guess you could rename it to RepeatToArray, but you'd possibly need an RepeatToList as well, and just naming it Repeat and returning an IEnumerable and then calling ToArray is almost the same...
Also, your Repeat extension method extends every possible object in .NET, which isn't a very good practice.
I imagine you don't need it everywhere, so maybe an internal extension method would be better.
Or it would need its own namespace so you always have to explicitly import it.
Having said all that, I prefer the second method.
To me, it's the best readable version and also the best performant in terms of memory and CPU (theoretically, because we're talking nanoseconds here).
|
|
|
|
|
Option 4:
Type[] expectedTypes = { typeof(string), typeof(string), typeof(string) }; No need to repeat the element type, or add the new[] keyword.
ToArray[^] delegates to the internal Buffer<TElement>[^] class. If the input implements ICollection<TElement> (which the result of Repeat doesn't), it declares and returns a single array of the correct size. Otherwise, it starts with an array of four elements; doubles the size each time it runs out of room; and then allocates a final array of the correct size once it's finished.
It's obviously not a huge extra overhead in this case. But it could add up if you're calling the code many times. And I don't think it really makes the code any clearer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
you 'da man !
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
@Marc-Clifton
Hi Marc, I am wondering why you'd ever need a collection where each item is a pointer to the same Type.
cheers, Bill
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 27-Feb-20 3:05am.
|
|
|
|
|
Pic [^]
I'll bet the guy who was driving along when it happened had to make judicious use of cleaning materials.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Mark_Wallace wrote: the guy who was driving along when it happened
This doesn't exactly look like a busy 4-lane highway to me...I'd say it would've been dumb luck if there was anyone around at all when it did happen.
|
|
|
|
|
Out in the sticks, here, families have owned the land either side of each road for well over a thousand years, and they don't like giving up even a few inches, so many of the roads, even busy ones, are pretty much the same width as they were when horses were the height of travelling technology.
In the town where I live, only one main road has been made wide enough for two cars (or one car and a tractor) to pass each other comfortably.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|