Real World Use of the keyword In in .NET Framework - contravariance

I have accidentally come across the keyword "in". I read an article on MSDN - in (Generic Modifier) (C# Reference) but still don't quite understand why it is useful. Can someone provide a real world example to show the reason why the keyword "in" is useful?
Thanks.

Related

Primary source for WoW lua API?

I've been looking for first-hand information on the World of Warcraft addon API. There are a couple wikis that are pretty good, but their reference links only point internally. Surely there is some information published by Blizzard on the topic.
Can all of their information really be gleaned from reverse-engineering and forums? That would be hard for me to believe.
Its not all necessarily gleaned from inspection or trial and error. Some is provided, but randomly, from "heads up" posts in the forums from "the source", as in Blizzard employees. They are usually pretty good about it, though is almost always provided in a "just the essentials to save you some pain" sort of way.
Here's an example:
http://blue.mmo-champion.com/topic/233590-mop-changes/
Watching for the "Blue" posts goes a long way, and its been this way for a long time. If you look at someting like this (old 3.1.0 end user patch notes) http://us.battle.net/wow/en/game/patch-notes/3-1-0 , and then scan to near the bottom there will be a note and link for API changes, so its easy to glean their intent on this, and that they intend to provide some "unofficial" support about API changes there whilenot burdening the actual product readme with them.
In general, I'd say that due to the very open nature of the materials, the source for the UI, very little is hidden and most is pretty self-evident, so it sort of barely qualifies as reverse engineering. Once you understand the Lua relationship to the general design of the WoW UI and supporting API, it's much easier.
As for the implied question about "why", the "hard to believe" part. They are doing, in my estimation, what they believe is the best balance between fully supporting without "officially" suporting, and not wasting cycles trying to document a huge amount of available facilites thats ever changing. I think they belive it makes a better product, having the ability to customize, so its intheir interest, however is frought with problems and even legal issues from many angles to be expressly "official" about it or to try to maintain coherent docs.
----
Toward the question "git hub" below, here is the "blue" post in context, which can be found by clicking the "blizz" link icon on the mmo-champion link provided before: http://us.battle.net/wow/en/forum/topic/6413172918#1 I was trying to give an example of a Blue post that had detail, but I accidentally gave one for the Web API not the Game API. However the principle is the same, and provides more Blizzard to Community context for dev support.
So basically that particular post was in reference to changes in the Web API, and the Git remark has no relevance to the game UI Customization and Macro thing. There is no hidden or official doc source for game UI Customization and Macro. Mostly its because it simply doesnt exist for anyone. :)
Yes, all the information is gleaned from the source.
Blizzard doesn't post the API information at this time, AFAIK.
http://www.wowpedia.org/Portal:Interface_customization is likely to be your best resource.
There are multiple ways to discover the names of callable C functions exported into the Lua environment.
But yes. One quite simple one would be to enumerate all the globals in the source that are written to, then enumerate the globals that are exposed while WoW is running - and take the difference, perhaps limiting the result to globals of type 'function'
Blizzard used to informally document its API for a while, but it has always been 'unsupported'
There are other ways to discover the API - but they involve doing things which may violate the TOS.
There is a website now that contains the API for wow addons. This has been helping me a lot.

Is it possible to convert F# code to C# code?

The reason why I am asking is that I'm learning F# and would like to attend TopCoder competitions. However, F# is not among the list of languages supported there. But C# is on the list (to be honest, this is the case for almost all online coding competitions, except Google Code Jam and Facebook Hacker cup).
The possible workarounds I can think of at this moment are
1) find a translator that can translate F# source code directly into C#
2) compile F# code into .net executable first, then disassemble it back to C# code
The minimum requirement is that the generated C# must be able to compile into a runnable .net executable, preferable as less external dependency as possible.
The first approach seems unlikely, a quick google search turns out nothing relevant.
Approach two looks more promising, there are .net disassemblers exist.
I tried the most popular one --- Reflector from Red Gate. While it can perfectly dissemble C# executables, it appears to have problems with executables compiled from F#: it happily disassembled, but the resulting C# code has some special characters such as adding a leading $ sign to a class name and other weird stuffs, so it cannot be compiled. I was using Visual Studio 2010 Professional, the latest Reflector beta version (which is free).
Am I missing anything here? Is it possible?
Update:
It looks like this is still impossible. For now, I'll use C# instead.
As others already pointed out in the comments - if there is some way to do that, there will be quite a few nasty cases where it probably won't quite work and it will be very fragile...
One way to deal with the problem (for you) is to just write the solution in F# and then rewrite it to C#. This may sound stupid, but there are some advantages:
In F#, you can easily prototype the solution, so you'll be able to find the right solution faster.
When translating code to C#, you'll probably find yourself using features like lambda expressions more often, so it may even improve your C# skills...
If you rely on .NET libraries, then this part of code will be easy to translate.
Of course, the best thing would be to convince the organizers that they should support F# (which probably wouldn't be too difficult if they allow C# already), but I understand that this may be a challange.

F# coding style and standard

While there is no One True Correct Style, some points of general agreement exist in the C# community regarding coding standard / style; usually, they are variations of the .NET Framework Design Guidelines.
When you look into F#, though, the standard is visibly different from what is considered normal in C#. As an example, the functions accessible on List or Seq (almost) all start in lower case: List.fold, List.map (but List.Cons and List.Empty don't...), whereas it is usually accepted that a method or property in C# should be capitalized.
So my question is, are there widely accepted coding conventions for F#? Is there an equivalent to the Framework Design Guidelines, or a good coding standard out there? And, as a bonus, in the whitespace-based F# world, do people have topics to argue endlessly about, similar to the timeless C# curly-brace position?
The F# team has drafted a document that sounds like exactly what you're asking for. (We're currently in the process of incorporating feedback from community/insiders we've sent the draft to.) It is likely to be published in the near future. I'll be sure to link it here when it's published.
EDIT
The document is archived now and you should consult the updated version instead.
There's also a section of the MS docs that's derived from itL https://learn.microsoft.com/en-us/dotnet/fsharp/style-guide/component-design-guidelines
Update #2: There is now an F# Style Guide on Microsoft Docs. This contains new material and also incorporates the material I linked to in Update #1 below.
Update #1: Don's paper (linked below) has been removed from the Microsoft site. However, A comprehensive guide to F# Formatting Conventions appears to be based on the same paper.
Don Syme's F# Coding Guidelines paper deals with the "curly-brace" formatting style issues for F#.

Is there anything "objective" about C# 4.0, or ruby-like?

This is a very "high-level" question. I'm looking for insight into this problem that c# has.
It has so many features that it supports almost ANY task, alas there are alternatives that are better suited for some tasks.
With the advent of MVC(old news) + ruby, people are starting to have "fun" AND getting things to work.
C# seems like a "get it done" language. It has so many libraries that knowing what to use has become more important than anything else.
So... IF one had to use C# to develop an "objective" oriented design AND having a ruby-like fun doing it... What features would best suit this "style"?
//C# 4 included//
PS. By objective i do not mean object oriented. "The Objective-C model of object-oriented programming is based on message passing to object instances. In Objective-C one does not call a method; one sends a message."
If you really want to use .NET and the 'Ruby' style, then why not try IronRuby?
The closest thing is could find is CCR and DSS.
Check you VPL on Microsoft Robotics Studio 2008 R3.
This approach seems to best fit the message-passing "feature" and promises to "objectivize" .net development.
This was a VERY interesting read on the subject:
http://blog.wekeroad.com/2010/08/09/csharps-new-clothes

Concise description of the Lua vm?

I've skimmed Programming in Lua, I've looked at the Lua Reference.
However, they both tells me this function does this, but not how.
When reading SICP, I got this feeling of: "ah, here's the computational model underlying scheme"; I'm trying to get the same sense concerning Lua -- i.e. a concise description of it's vm, a "how" rather than a "what".
Does anyone know of a good document (besides the C source) describing this?
You might want to read the No-Frills Intro to Lua 5(.1) VM Instructions (pick a link, click on the Docs tab, choose English -> Go).
I don't remember exactly where I've seen it, but I remember reading that Lua's authors specifically discourage end-users from getting into too much detail on the VM; I think they want it to be as much of an implementation detail as possible.
Besides already mentioned A No-Frills Introduction to Lua 5.1 VM Instructions, you may be interested in this excellent post by Mike Pall on how to read Lua source.
Also see related Lua-Users Wiki page.
See http://www.lua.org/source/5.1/lopcodes.h.html . The list starts at OP_MOVE.
The computational model underlying Lua is pretty much the same as the computational model underlying Scheme, except that the central data structure is not the cons cell; it's the mutable hash table. (At least until you get into metaprogramming with metatables.) Otherwise all the familiar stuff is there: nested first-class functions with mutable local variables (let-bound variables in Scheme), and so on.
It's not clear to me that you'd get much from a study of the VM. I did some hacking on the VM a while back and it's a lot like any other register-oriented VM, although maybe a bit cleaner. Only a handful of instructions are Lua-specific.
If you're curious about the metatables, the semantics is described clearly, if somewhat verbosely, in Section 2.8 of the reference manual for Lua 5.1. If you look at the VM code in src/lvm.c you'll see almost exactly that logic implemented in C (e.g., the internal Arith function). The VM instructions are specialized for the common cases, but it's all terribly straightforward; nothing clever is involved.
For years I've been wanting a more formal specification of Lua's computational model, but my tastes run more toward formal semantics...
I've found The Implementation of Lua 5.1 very useful for understanding what Lua is actually doing.
It explains the hashing techniques, garbage collection and some other bits and pieces.
Another great paper is The Implmentation of Lua 5.0, which describes design and motivations of various key systems in the VM. I found that reading it was a great way to parse and understand what I was seeing in the C code.
I am surprised you refer to the C source for the VM as this is protected by lua.org and the tecgraf/puc rio in Brazil specially as the language is used for real business and commercial applications in a number of countries. The paper about The Implementation of lua contains details about the VM in the most detail it is permitted to include but the structure of the VM is proprietary. It is worth noting that versions 5.0 and 5' were commissioned by IBM in Europe for use on customer mainframes and their register-based version have a VM which accepts the IBM defined format of intermediate instructions.

Resources