π The Evil Ideas thread
-
Maybe. Everyone around me seems to believe I'm capable of some kind of magic but I'm not seeing it.
-
Maybe. Everyone around me seems to believe I'm capable of some kind of magic but I'm not seeing it.
It's called "Knowing how to use Google". It's a rare skill known only to "computer wizards" who are capable of such magics as searching for "ATI Radeon druver Windows 7". And then downloading it!
Edit: Also, we know Google will fix out typos. So I'm not gonna fix mine.
-
Computer wizards don't go to hogwarts, so my point stands.
-
No, not that magic. I'm talking about the magic between 'using Google' and 'building it yourself'
-
No, not that magic. I'm talking about the magic between 'using Google' and 'building it yourself'
Ah, now you're talking about the self-conscious magic. But for most people installing a driver/application and writing a driver/application is the same level of magic.
-
Exactly. Everyone else around me is convinced I have the self-conscious magic but I don't see it.
-
We already have to write shims everywhere. And we do it without the benefit of relying on a type system to ensure type correctness. Why not make it easier? That is a whole class of tests you can just stop writing.
-
Speaking of which, the code I'm writing right now is effectively that.
Building a List in C#, only to call .ToArray() on it, just so I can pass it onto the next link in the chain that won't accept Lists.
Just for context: this is terrain generation for a lunar lander. I don't yet know how many points will be in the terrain thus I need a variable length array but C# doesn't have those, thus a List, only to make an array out of it.
-
I don't know C#, but surely, it has a simple conversion function for that case.
Haskell has an entire ecosystem of "fromDataStructure" functions. (Not my favorite part of the language, but at least you can get from A to B to C just by composing them --
Seq.fromList . Set.toList :: Set a -> Seq a
--::
is read "has type")
-
Sure it does, .ToArray(). The thing is, I feel like this is a mess because I'm having to build it in one thing and convert it to another because the destination type isn't ideal.
My choices are to build it as a List and then convert it to an array or over-declare the array up front. Neither seems optimal.
-
Do C# lists know their lengths? Or can it fuse list operations? If so, don't worry about it. Use the types for their semantics. Convert between types when the types don't fit the semantics.
-
Yes, they do, but that's mostly irrelevant; the List class has a handy .Add method for that sort of thing and a .Count property to tell you how many items are in it.
That's the thing... I want to use an array, that's what the next part of the chain wants (and that's code I don't want to modify since that means a major overhaul of a third party component that expects an array). But arrays are fixed length and that's all they are. So my choices are as outlined: overdeclaring an array or juggling types for no reason other than satisfying what feels like semantics.
All I'm dealing with is a list of objects whose length isn't known at the start. In other languages, I'd just say "I want a list of things" and be able to pass that list around without any problem because a list would be a list would be a list - but in C#, there are different kinds of lists, depending on whether they're fixed length or variable length and they're different objects with different methods, and while one can switch between them, this seems like fuss that shouldn't be necessary.
But maybe that's because I've spent most of the last 11 years doing PHP where everything is crazy flexible anyway.
-
Oh, I get it.
But lists are slow. Arrays are fast. I'm sure your consumer wants an array because of that property.
You would be stuck using a slow list in a language where a list is a list is a list. Instead, you get to use a list to construct your array.
-
Hmm, perhaps. It doesn't help that this isn't really explained anywhere and my sum total of introduction to C# was API gluing other C# scripts in Unity and MonoDevelop (I used to do all my Unity stuff in JS but then I discovered the performance difference between them in Unity, i.e. one gets compiled and the other doesn't)
-
Editing
.git/refs/heads/master
straight in production, while everyone's asleep, to hide a mistakenly pushed commit.Who would do such a thing?
Filed under: ; what's a reflog?
-
But lists are slow. Arrays are fast. I'm sure your consumer wants an array because of that property.
FYI, a List in C# is an array-backed data structure, so it still has O(1) random access. The List datatype adds dynamic reallocation so that you're not required to know the size of things before working with them; it's probably using an amortized linear algorithm for the common case of appending single items. (I've not checked this, but the algorithms for doing it are very well known in the procedural/OO community even before C# was created, so failing to use them would have been TRWTF.)
ArrayList and Vector have similar properties in Java. Just different naming (in Java, List is the abstract type that they both implement.)
-
ArrayList and Vector have similar properties in Java. Just different naming (in Java, List is the abstract type that they both implement.)
Vector is just ArrayList with
Lock(this)
around every method, isn't it?
-
Oh, I get it.
But lists are slow. Arrays are fast. I'm sure your consumer wants an array because of that property.
You would be stuck using a slow list in a language where a list is a list is a list. Instead, you get to use a list to construct your array.
Actually, I'm pretty sure in C# List uses an array as its backing storage. The only thing extra it does is handle automatic resizing. Should be pretty much the same speed, with some (small) memory overhead.
-
Source Engine has a class named Vector, which stores 3 floats, and a class named CUtlVector, which is an ArrayList. They use
vec
as the prefix for variables of either type, which gets really confusing when you have a list of positions and you're accessing members of that list.
-
Which is kind of my real problem with List being what it is. Still, that's the language I'm choosing to work with because the other two languages in Unity kind of suck ass.
-
-
That's an evil idea indeed.
-
Correct. There are a few other classes like that, such as StringBuffer and Hashtable.
-
Vector is just ArrayList with
Lock(this)
around every method, isn't it?Yeah. It was a design fuck up; though not one that was particularly obvious at the time (nobody had so much experience with threaded use of data structures back then). It turns out that most of the time you either don't need locking (because the object isn't shared between threads in the first place) or you need to be more careful with the lock scope. It's a shame on one level, since if it had been possible to get the locking right at the API level, it would have prevented ever so much trouble.
I can understand why they fixed it the way they did though. βDon't break existing code if you can help itβ is a good rule for language designers. Someone might have been using the locking right, so shouldn't have their code invisibly broken.
There are a few other classes like that, such as StringBuffer and Hashtable.
They're good things to search for as part of basic optimisation/cleanup when taking over a codebase from someone elseβ¦
-
Create 3-5 new accounts
Automatically flag items in the recent activity section
-
-
New accounts don't have the ability to flag.
-
And plus, that seems like something that deserves a human solution.
-
Oh look. A bootstrap-style dropdown and it's alignment is utterly broken.
I think I might know which plugin that is. Freaking thing, had to fix it's CSS in several places already.
-
Sure, but you don't have to post anything to become a non-new account. You've said it yourself several times.
-
This topic:
http://what.thedailywtf.com/t/the-fa-spin-testing-thread/1481
Seriously. It now causes a memory leak, in FF at least, that doesn't stop if you leave the topic. You need to restart the damned thing.
I'd congratulate the bastard who did it in there, but memory leak and all...
-
This topic:
http://what.thedailywtf.com/t/the-fa-spin-testing-thread/1481
Seriously. It now causes a memory leak, in FF at least, that doesn't stop if you leave the topic. You need to restart the damned thing.
Seems to be fixed or at least not to affect firefox 30 on fedora 20 with lxde as desktop.
-
What, the browser with only one process?
-
Arantor's Law of Internet Discussions: If going Full Godwin is too much to make your point, quote Shakespeare at them.
-
Brevity is the soul of wit, @Arantor.
-
Am I known for my brevity?!
-
Hence why I am telling you this.
-
Arantor's Law of Internet Discussions: If going Full Godwin is too much to make your point, quote Shakespeare at them.
https://www.youtube.com/watch?v=XSqCJ-UGYns&feature=youtu.be&t=4m2s
-
Sadly, half-wits are seldom briefer than those possessed of a full wit.
-
Hence why I am telling you this.
I dare do all that may become a man;
Who dares do more is none.@Onyx, I see your Plummer quote and raise you a slightly earlier clip:
http://www.youtube.com/watch?v=fg58hVEY5Og#t=0m29sSadly, half-wits are seldom briefer than those possessed of a full wit.
I'm somewhere like 3/4 on the scale.
-
@Onyx, I see your Plummer quote and raise you a slightly earlier clip:
I was going for Bones' quote. But I do have to say that spinning in the chair is the way to perform Shakespeare.
Now, if it only were in original Klingon...
-
-
I like how the quoting ignores the code markup, but not the sharp markup.
-
A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines. -- Emerson
-
#define true 1 #define false 0 #define returntrue false #define returnfalse !false #define strcmptrue false #define strcmpfalse !false #define FILE_NOT_FOUND -0.0
CTFY
-
Consistent inconsistency, Discourse, +1, yadda yadda
-
testing
#define true false
-
What you need is to escape the hash.
#define true false
Because using a backslash as an escape character is completely discoverable in a forum context.
*also works on Markdown*
-
Do I need to escape the backslash when I'm escaping the hash?
# not real code obj.something('\\n')
-
No, you don't need to escape it when you're doing code. But you do need to escape it to be normal to prevent Markdown being special.