Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Gul Banana
Nov 28, 2003

here's an irritating vb.net parsing ambiguity: as parentheses are used for so many things, it can't compile this code:

code:
Property F As Action
F()
although this is fine:
code:
Property F As Func(Of Integer)
Dim x = F()

Adbot
ADBOT LOVES YOU

Gul Banana
Nov 28, 2003

ljw1004 posted:

F()() works.

lol what
I'd gone with F.Invoke(), so it's nice to have an alternative that doesn't betray the delegate-ness of the code - but how on earth is that parsed? one set of parens is the invoke, and the other.. a unit expression it's applied to? empty generic clause??

Gul Banana
Nov 28, 2003

ok, i've got it: VB.NET has indexed properties. you can write
ReadOnly Property F(s As String) As String

F("s") would invoke the getter. by analogy, you can call an UNindexed property like: F(). then the subsequent () are just the delegate invocation...

Gul Banana
Nov 28, 2003

we were passing around some of those screenshots excitedly at work today :)

actually, i spent some time installing VS2015 in a vm to try and try it out - unfortunately it won't build our main solution yet, something about the package-restore-less workflow is upsetting to it. these perf tools are a great carrot to keep trying!

Gul Banana
Nov 28, 2003

oh poo poo, just heard the news that asp.net 5 (vNext) will not support vb.net
perhaps this will be the catalyst for me to escape it at last

Gul Banana
Nov 28, 2003

Presumably the relevant team took a look at their userbase, decided VB.NET wasn't worth the extra effort, and secured an exemption from whatever internal mandate has previously governed such things...

Or do you mean technically "how"? It doesn't use msbuild, or the csproj/vbproj system. There's a new build+runtime system called K, which runs on top of .NET, Core CLR, or Mono; it uses project.json files, special in-memory compilation and change detection for reload workflow, it's cross platform.. they even have some actual mods to C# itself, like [AssemblyNeutral]. You can reference, say, a nuget package containing a dll implemented in VB or F# - as long as it is written as a PCL for .net4.6+coreclr, assuming those exist now - but you can't use any language other than C# in the actual web projects or in dependencies that use K to build.

Gul Banana fucked around with this message at 02:21 on Feb 1, 2015

Gul Banana
Nov 28, 2003

Gul Banana posted:

a PCL for .net4.6+coreclr, assuming those exist now
it seems they don't. Now that's a pain no matter what language you're using, and probably a dealbreaker for us porting anything to Core CLR at work. We're not going to turn project references into nuget packages with a custom unzip/repack system just to use within a solution.

Gul Banana fucked around with this message at 02:48 on Feb 1, 2015

Gul Banana
Nov 28, 2003

code:
' This must be of func type to work around a compiler error where the anonymous function type is unconditionally instantiated for delegate conversion despite having been subsequently nulled
-- me just now :-(

Gul Banana
Nov 28, 2003

Yeah, I had a conversation with David Fowler. He stated pretty clearly that they're not going to support languages other than C# in KRuntime projects (actual asp.net sites and new-style class libraries).
This issue got me interested: https://github.com/aspnet/Home/issues/236

@davidfowl confirmed no vb support, and that also if those extensibility points do get created, they won't be used by Microsoft for vb support. However, they do intend to provide some way to reference projects written in VB/C++CLI/etc FROM asp.net projects, certainly if you're targetting the desktop .NET framework and "not yet" otherwise. Right now, referencing VB projects isn't working even for targeting net45, but they will definitely support at least that much.

Gul Banana
Nov 28, 2003

drat, they must have some pretty specialised workflow for handling that particular file

Gul Banana
Nov 28, 2003

Ochowie posted:

I haven't used VB since v1 of the .NET framework before I learned C#, but drat that is an incredible departure from the original principles of the .NET framework.

The impression I got from talking to some of the developers was that they're committed to enabling things which were just impossible before - side by side installs, cross-platform support, fine-grained versioning (and therefore first-class package management). In order to do that, they're making sacrifices. In a way, it's the same old Microsoft story - reaching for the markets you *don't* have, because that's where the growth is! Still, I don't think they've made a bad decision overall. The combination of the new runtime and new build systems really open up the possibilities for .NET, and the old stuff will work 'forever' in the same sense that e.g. winforms and webforms are still supported today.

Going single-language in particular... I'm less convinced of the wisdom there. Although personally I'm going to take the chance to jump to the ship I wanted anyway, I think they've been misled by their target audience. When the open source and web development communities talk about this stuff, they think of C# as .NET - the news of VB being dropped hasn't really got out in a big way, but there will be segments for whom it is not news at all. A lot of people just do not even know why VB.NET exists (or even understand how little related it is to VB6). So there's a loop there - the K team are making their own lives a lot easier and the early feedback tells them they're doing 100% fine.

Meanwhile, where .NET is used today is largely enterprise - it's big! Not as big as Java, but still big. And very lucrative. And those people have a *lot* of VB code, or in some cases more esoteric stuff like: financial systems in F#, interop in C++/CLI, scripting whatnots in IronPython. This is a huge audience which is just going to be cut off from the new world - at least, the web development part of the new world. It only makes sense if Microsoft have judged that those legacy desktop and server systems would have to be rewritten rather than ported *anyway*. I'm sure in many cases they'd be right.

Of course, it's all a bit confusing because there's some internal misalignment going on. The compiler people seem to like multiple languages just fine, and VB's supported in Roslyn and in Universal apps...

Gul Banana
Nov 28, 2003

also not supported in the new asp.net: T4 templates :(
I think those are actually *more* important to us than existing non-C# source code. oh well, it's just a matter of putting them in their own old-style project and referencing it via nuget.

Gul Banana
Nov 28, 2003

if you want it 'detached', observe it on your event loop/in main()
otherwise yes, save the task then await it after the other.

Gul Banana
Nov 28, 2003

Your call stack explains the reason why it's trying to get the server version - New Relic is using it for analytics. You might have encountered a bug triggered by reentrancy, as i see that ServerVersion.get is ultimately being called within OpenConnection thanks to the analytic shim... does that require a connection to be already open? Does it open one itself? Either would be bad.

Gul Banana
Nov 28, 2003

Ochowie posted:

This might be a dumb question but what's the intended deployment scenario with ASP.NET 5.0 (previously vNext)? The documentation states that it can be self hosted or hosted in IIS. So that leaves me wondering if the intended Mac and Linux deployment scenario is really supposed to be the self hosting approach. I always thought this sort of thing was for development and debugging only (kind of like Flask self-hosting) and that production should go through Apache or NGinx or something.

they're writing a libuv-based http server named Kestrel
put it behind nginx and it's no worse than how people host a lot of random stuff

Gul Banana
Nov 28, 2003

just use Regex.Matches, which returns a collection straight up

Gul Banana
Nov 28, 2003

anyone know a way to build a nuget package with a stable version which can use, as a dependency, something with a prerelease version?

Gul Banana
Nov 28, 2003

Ithaqua posted:

Whether you can or not, that seems like a really bad idea for the obvious reasons.

Turns out the way to do it to use explicit dependencies in your nuspec - rather than relying on nuget pack to include the dependencies you've got in packages.config. You then configure their version as half-open intervals, like this:
Version="(1.0.0,2.0.0]"
That'll match, say, 2.0.0-rc1 as well as 2.0.0, and it doesn't prevent you from giving your own package a stable version.

Gul Banana
Nov 28, 2003

Inverness posted:

I'm looking into MEF and getting pretty confused with the versioning.

I'm seeing things that say MEF came with .NET 4 and MEF 2 comes with .NET 4.5, but I also see the MEF 2 NuGet package which contains a portable implementation.

Is this a case of having the "full" MEF 2 with .NET 4.5 and a lightweight MEF 2 subset on NuGet?

not quite; .NET 4 and 4.5 both have "MEF 1", although the 4.5 version has more features and bug fixes. "MEF 2", aka Microsoft.Composition, is the standalone package, which can also run on .net 4 and 4.5, as well as on system.runtime/PCL platforms.

MEF 2 isn't a subset so much as a rethink. it adds as well as removes features.

Gul Banana
Nov 28, 2003

nuget is not magic and you will waste more and more time if you refuse to use it, since everything's coming to rely on it

maintaining build scripts and nuspec files requires at most a small chunk of one engineers time. setting up a symbol server took us about a day and it works consistently

Gul Banana
Nov 28, 2003

i'm looking forward to finding out the final details on 'plibs' or whatever they end up called, the replacement for pcls that work with .net core..

Gul Banana
Nov 28, 2003

Factor Mystic posted:

I also wish WPF would become less bad, so we agree on that point. However, you can take your xaml & data binding & mvvm principles and use them to build universal apps which are now much more integrated with the desktop.

Weeeell.. the Windows 10 desktop. Windowed WinRT isn't being backported to even 8, is it? That means a lot of us are stuck with WPF for many years to come.

Originally, when .NET came out and took over the LOB world, it was at least in part because it supported platforms that were currently in use, not just ones that would likely eventually get some.

Gul Banana
Nov 28, 2003

Visual Studio Code is a really interesting idea which got less interesting when it was revealed that a) it's an Atom-like html app which can't open large files, and b) it doesn't have as much intellisense support as even OmniSharp provides.

Gul Banana
Nov 28, 2003

Kekekela posted:

It seems like you think Atom is bad, which is also kind of the vibe I get from other people whose technical opinions that I value. Can you elaborate on why if its not too off-topic? (or is it just the large files thing?)

I've been trying to transition to doing more of my non-VS development on my macbook and I've been using Atom. I'd switched to it a couple months ago because Sublime made me feel guilty about being cheap. Mainly its smaller github projects and files for now and Atom's been great. If I'm going to run into a wall with it though, I'd like to know now rather than later so I can shift to a plan B. (which I guess would be Webstorm or back to Sublime)

If Atom works for you that's fine. I just prefer the native controls & performance that you get from a lower-level editor. Using HTML5 by preference for UI development is just.. a weird trend that I don't fully understand; it's like people learned javascript and don't want to ever go beyond that, despite its disadvantages for complex applications. A text editor *seems* simple, but a good programming editor has a lot of features these days.

Performance is a specific concern - I have some 4 MB .cs files here, 90k lines or so of generated code. My machine is also bogged down with virtual machines, conference calls and debug utilities.. I don't want to have to worry about a mess of DOM spans for just my editor windows.

Gul Banana
Nov 28, 2003

man, i want higher-kinded delegates

how cool would it be to be able to implement this interface:
code:
interface IFoo {
    Foo<T>();
}
with this closure-accepting impl:
code:
class DelegateFoo: IFoo {
  private Action<<T>> f;
  public DelegateFoo(Action<<T>> f) {
    this.f = f;
  }

  public Foo<T>() {
    f();
  }
}
where <<T>> is hypothetical syntax for a parameterised type constructor.

Gul Banana
Nov 28, 2003

RICHUNCLEPENNYBAGS posted:

Call me stupid but what are you getting here that you don't get with abstract classes and protected members?

abstract classes don't let you write an inline closure either. here's the general use case for Delegate____ impls:

C# code:
    class FormulaTester
    {
        public void Test(IFormula f)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("{0}({1}): {2}", f.Name, i, f.Calculate(i));
            }
        }
    }

    interface IFormula
    {
        string Name { get; }
        int Calculate(int i);
    }

    class DelegateFormula : IFormula
    {
        private string n;
        private Func<int, int> f;

        public DelegateFormula(string n, Func<int,int> f)
        {
            this.n = n;
            this.f = f;
        }

        public string Name
        {
            get { return n; }
        }

        public int Calculate(int i)
        {
            return f(i);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var tester = new FormulaTester();

            var changeAmount = 1;
            tester.Test(new DelegateFormula("inc", x => x + changeAmount));
            tester.Test(new DelegateFormula("dec", x => x - changeAmount));
            tester.Test(new DelegateFormula("const", x => changeAmount));

            Console.ReadKey();
        }
    }
they let you write multiple concise implementations with access to local data via closures.

now, what happens if i want to add a type parameter? let's say that IFormulas can operate on a T instead of an int? still works:
C# code:
    class FormulaTester
    {
        public void Test<T>(IFormula<T> f, T[] testdata)
        {
            foreach (var datum in testdata)
            {
                Console.WriteLine("{0}({1}): {2}", f.Name, datum, f.Calculate(datum));
            }
        }
    }

    interface IFormula<T>
    {
        string Name { get; }
        T Calculate(T i);
    }

    class DelegateFormula<T> : IFormula<T>
    {
        private string n;
        private Func<T, T> f;

        public DelegateFormula(string n, Func<T,T> f)
        {
            this.n = n;
            this.f = f;
        }

        public string Name
        {
            get { return n; }
        }

        public T Calculate(T x)
        {
            return f(x);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var tester = new FormulaTester();
            var data = new[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var changeAmount = 1;
            tester.Test(new DelegateFormula<int>("inc", x => x + changeAmount), data);
            tester.Test(new DelegateFormula<int>("dec", x => x - changeAmount), data);
            tester.Test(new DelegateFormula<int>("const", x => changeAmount), data);

            Console.ReadKey();
        }
    }

Gul Banana fucked around with this message at 09:12 on May 11, 2015

Gul Banana
Nov 28, 2003

so those are the basics. now we want something fancy. i want programmable swapping/locking strategies, using generics; i'm going to have the tester supply inputs and print whichever one comes back. i can do that for concrete implementations:
C# code:
    class Box<T>
    {
        public T x {get; set;}

        public override string ToString()
        {
            return x.ToString();
        }
    }

    class FormulaTester
    {
        public void Test(IConcurrentFormula f)
        {
            var i0 = new Box<int> { x = 0 }; var i1 = new Box<int> { x = 1 };
            Console.WriteLine("{0}(0, 1): {1}", f.Name, f.Calculate(i0, i1));
            Console.WriteLine("{0}(1, 1): {1}", f.Name, f.Calculate(i1, i1));

            var d0 = new Box<double> { x = 0 }; var d1 = new Box<double> { x = 0 };
            Console.WriteLine("{0}(0.0, 1.0): {1}", f.Name, f.Calculate(d0, d1));
            Console.WriteLine("{0}(1.0, 1.0): {1}", f.Name, f.Calculate(d1, d1));

            var c0 = new Box<char> { x = '0' }; var c1 = new Box<char> { x = '1' };
            Console.WriteLine("{0}('0', '1'): {1}", f.Name, f.Calculate(i0, i1));
            Console.WriteLine("{0}('1', '1'): {1}", f.Name, f.Calculate(i1, i1));
        }
    }

    interface IConcurrentFormula
    {
        string Name { get; }
        T Calculate<T>(T left, T right) where T:class;
    }

    class SwapFormula : IConcurrentFormula
    {
        public string Name
        {
            get { return "swap"; }
        }

        public T Calculate<T>(T left, T right) where T : class
        {
            return Interlocked.Exchange(ref left, right);
        }
    }

    class CompareAndSwapFormula : IConcurrentFormula
    {
        public string Name
        {
            get { return "cas"; }
        }

        public T Calculate<T>(T left, T right) where T : class
        {
            Interlocked.CompareExchange<T>(ref left, default(T), right);
            return left;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var tester = new FormulaTester();
            
            tester.Test(new SwapFormula());
            tester.Test(new CompareAndSwapFormula());

            Console.ReadKey();
        }
    }
but... how do we write DelegateConcurrentFormula? it looks something like this:
C# code:
    class DelegateConcurrentFormula : IConcurrentFormula
    {
        private string n;
        private ??? f;

        public DelegateFormula(string n, ??? f)
        {
            this.n = n;
            this.f = f;
        }

        public string Name
        {
            get { return n; }
        }

        public T Calculate<T>(T left, T right) where T : class
        {
 	        return f<T>(left, right);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var tester = new FormulaTester();
            
            tester.Test(new DelegateConcurrentFormula("swap", (left, right) => Interlocked.Exchange(ref left, right)));
            tester.Test(new DelegateConcurrentFormula("cas", (left, right) => Interlocked.CompareExchange(ref left, right, right)));

            Console.ReadKey();
        }
    }
there's no actual type you can write for f. hypothetically it would be something like Func<T><T>, that is, the type of a function which has a type parameter T and which returns a value of that type T. this is a "rank 2" or "higher-kinded" type, and it doesn't exist on the CLR.

Gul Banana fucked around with this message at 09:12 on May 11, 2015

Gul Banana
Nov 28, 2003

ljw1004 posted:

I like the way you wrote that out and built up reasonable cases. My thoughts:

A instance of a delegate is basically an instance of a class with a method on it -- and that's how it's implemented under the hood -- but with the limitation you describe about generics.

Option 1 is to introduce higher-order types to the language and to the CLR, so that field "f" would be a higher order delegate type.

Option 2 is just to ask coders to write it out longhand, as you have done, and field "f" can be of type IConcurrentFormula.

All round, Option2 seems the nicer choice! More in keeping with object oriented design! and a much simpler language!

Yeah, I don't realistically expect this feature to be added - at minimum there are other things that would benefit more people as well as being simpler. I just wanted to explain the concept, at least, without having to refer to Haskell type constructors :)

quote:

My other thought is that the job of the type-system is to help catch errors at compile-time rather than at runtime. For instance, the current effort by the VB/C# language design team to bring in "nullable types" and "non-nullable types" into the type system is a way to reduce the number of times that folks get NullReferenceExceptions and ArgumentNullExceptions at runtime. But it's always a tradeoff, and you can live in a more type-heavy world or a less type-heavy world.

In that light, question what a higher-order delegate actually means. A instance of a higher-order delegate Func<<T>><T,T> would be an instance that, for any type "T", it can take in an object of type "T" and will return one of type "T". There already exists this concept in object-oriented languages: Func<object,object>. This will work for any type "T", and will take in an object of that type, and can return one. You don't get the compile-time enforcement that an InvalidCastException won't occur at runtime, but in most cases you'd detect and eliminate such errors very early in your unit tests.

Actually, this doesn't cover my use case. See, the thing i was really trying to achieve is a 'generic visitor'. I have a set of types that all implement IThing (not actual name), and then an IThingInfo for each type- this is all backed by generated code. At runtime, we want to get the static type of a dynamically selected IThing impl, using its info. The mechanism I have for this is an interface IThingInfo.Visitor, similar to the usual visitor pattern but with a single Accept method which just calls Sub Visit(Of T As IThing)(). This means that we can then define a bunch of visitor implementations which, when visited, *receive the type parameter T* and go on to do more work with it.

The entire point is to recover type safety, and to gain access to apis like CreateThingListController(Of T As IThing)- so object or dynamic wouldn't help. However, this is all so esoteric that I didn't want to use it as the real example (although it is a real use case in heavily used code). What we do is write a bunch of SpecificActionTakingThingVisitor classes and wish occasionally that they could be inline.

quote:

Incidentally, why define your own "Box" type rather than using the "StrongBox" type in .NET ?
I didn't know about it :D
Looks like I should go poke around System.Runtime.CompilerServices someday!

Gul Banana
Nov 28, 2003

is anyone having a problem running built .net applications after the most recent round of windows updates? my programs are crashing in Task.Run - Run() itself, not the lambda that's passed into it!
the exception is the incomprehensible "Exception from HRESULT: 0xFEDF6408" - this code does not appear anywhere on the internet, and nor does the name of the method that throws it: AsyncCausalityTracer.TraceOperationCreation

looks like it's a call through a COM import into some CLR internals... :/

Gul Banana
Nov 28, 2003

system restore to pre-update fixed it. time to hold off on those patches a while

Gul Banana
Nov 28, 2003

it's a brittle test. you'd only be checking that the unit *does what it does*- not verifying that this is a correct or useful implementation.

Gul Banana
Nov 28, 2003

iirc async model binding for webforms specifically is being introduced in 4.6 - final release July 29
if your issues are on the backend you might not particularly need the binding to be async, though

Gul Banana
Nov 28, 2003

Factor Mystic posted:

"File>New>C#>Web>ConsoleApp/ClassLibrary" doesn't show .NET Core in the New Project window, but I see I can switch over to it in project properties. That's a bit weird but I can deal.

Not sure why normal desktop Console apps couldn't target .NET Core the way a "web" Console app can.

it's due to legacy and IP
the 'full' non-core framework is required for WPF, forms, etc because they are implemented in terms of windows-specific APIs. directx is used heavily, stuff like system.drawing uses GDI, system.web uses http.sys, etc.

the new core is open source and cross-platform- they don't want to open source and can't make cross-platform parts of the older stuff. asp.net 5 runs purely on the OSS code and can use things like IIS optionally as plugins. windows 10-specific (uwp) stuff runs on .net core + proprietary windows specific parts. it can be thought of as a refactoring of WPF so that the xaml layer exists 'above' the .net one.

(although this is an oversimplification and not actually true. uwp is really more like 'WPF reimplemented in c++/COM, with the environments including .net able to access its apis via 'projection' plugins. for windows 8, the .net projection was a custom vertical; now it is .net core)

Gul Banana
Nov 28, 2003

quote:

edit: removed my article, since the NuGet team are keen to explain this themselves in a few days -- can't wait!
:( well, I'm sure that writing it was educational at least

Gul Banana
Nov 28, 2003

just realised something rather sad- it looks like T4 isn't getting updated to C#6. i wanted to use elvis and so on in my templates :(

Gul Banana
Nov 28, 2003

Munkeymon posted:

You mean they're dropping support? Link?

t4 still exists and works (except in new xproj projects), but it has not been rewritten to use roslyn. it's based on the old compiler infrastructure, so when you write t4 in vs2015 you get C#5 level features only.

reading the tea-leaves of developer statements, it appears that the team(s) would prefer people migrate to razor. unfortunately, that's just a nice parser library which doesn't provide the same generalised & tool-integrated macro facility as t4.

Gul Banana
Nov 28, 2003

it doesn't sound like anything is gained by trying to make this particular api REST. it's not naturally resource based and request-object mapping is at odds with hateoas navigation.

is there some reason you want to use a RESTful style instead of just an RPC-style http api?

Gul Banana
Nov 28, 2003

i wasn't very clear before due to phoneposting, but mr. shiny pants has it right. there's nothing wrong with "just some endpoints where you can get stuff over HTTP" though- the implication is that it then doesn't matter much what the Right Way is, because it's whatever you make up.

people sometimes talk about "levels" of REST these days, which are like
level 1 - you're using http methods and json
level 2 - the api is oriented around resources rather than calls
level 3 - client application state transitions via discovered hypermedia

each brings you closer to a model which is in theory highly scalable, evolvable, etc, but is not actually necessary, particularly if you have only a single client and server.

Gul Banana
Nov 28, 2003

The Wizard of Poz posted:

Edit: I've just been doing some follow-up reading and I think I understand now. But to my naive eye, it looks as though virtually all of the "RESTful" APIs that I know of are not actually RESTful, if you accept HATEOAS as a prerequisite for RESTfulness. Is this right?

this is correct, the common definition has drifted & there's a lot of ongoing debate about the term's utility. if vagueblogging and subtweeting rise to the level of 'debate'.

Adbot
ADBOT LOVES YOU

Gul Banana
Nov 28, 2003

nuget in vs2015 is unusable crap :/

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply