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
twodot
Aug 7, 2005

You are objectively correct that this person is dumb and has said dumb things

Inverness posted:

Do you know why Microsoft isn't open-sourcing everything for Desktop too?
This is a good question, and I don't know the answer. I expect it's almost certainly just a matter of effort. Desktop has complicated features which we don't want to support, but have to because of compatibility, Fusion being the best example. Open sourcing Desktop sources isn't any extra work (edit: well reviewing pull requests is some work I suppose), but it kind of fucks with the branding if it's open source, but doesn't have the cross platform support. Also while .NET Native doesn't use coreclr.dll, the surface area it supports is the CoreCLR surface area, so I think there's a desire to move people in that direction.

twodot fucked around with this message at 23:12 on Nov 14, 2014

Adbot
ADBOT LOVES YOU

ljw1004
Jan 18, 2005

rum

Gul Banana posted:

Will T As {Structure, New} now be allowed? that'd let us differentiate between the stronger- and weaker-construction-guaranteeing types.

Your interpretation is correct.

Here's my understanding of your proposal. On the declaration side, if you're in a method body where you have "T As Structure" then you're allowed to do the things that call INITOBJ like "Nothing" and "default(T)" and arrays and List(Of T).Capacity, as normal. But when you have "T As {Structure, New}" then you're disallowed from doing anything that would call INITOBJ, and you're given assurance that T does have an explicit public parameterless constructor.

On the consumption side, if you try to pass a type TYPE1 as an argument for "(Of T As Structure)" then it works as normal. But if you try to pass TYPE1 as argument for "(Of T As {Structure, New})" then this is only allowed if either TYPE1 is a structure with an explicit public parameterless constructor, or TYPE1 itself is a generic type parameter with the {Structure, New} constraint.

The intent of your proposal is so that no one writes a parameterless constructor under the belief that this will always be called, but then does something that fails to call it. It's kind of strange because library authors will have to do the {Structure, New} work at no benefit to themselves, solely to help callers. Also strange because it doesn't catch INITOBJ cases done by the caller without going via generic methods. One unknown is whether the metadata format itself can accommodate both "New" and "Structure" constraints (i.e. whether their bitfields don't clash). A bigger unknown is whether it's possible to catch all things that might call INITOBJ both directly and indirectly. That seems really hard.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

Munkeymon posted:

If you mean Forms, I think that'd entail all of Windows from some of the stuff hackbunny has been saying in his YOSPOS thread.
I meant, Forms, WPF, and the whole Desktop CLR. :unsmigghh:

twodot posted:

This is a good question, and I don't know the answer. I expect it's almost certainly just a matter of effort. Desktop has complicated features which we don't want to support, but have to because of compatibility, Fusion being the best example. Open sourcing Desktop sources isn't any extra work (edit: well reviewing pull requests is some work I suppose), but it kind of fucks with the branding if it's open source, but doesn't have the cross platform support. Also while .NET Native doesn't use coreclr.dll, the surface area it supports is the CoreCLR surface area, so I think there's a desire to move people in that direction.
How does WPF factor into it? The lack of cross-platform WPF is the reason I can't swear off WinForms. Mono has WinForms wrap GTK+ or whatever on other platforms, so that is cross platform as much as a native GUI wrapper can be.

From my understanding, WPF uses MILCore at the low level to render everything with DirectX. I assume most of the work would be in making an OpenGL implementation of this for Mac and Linux. Most of the higher level stuff should work fine though, right?

Gul Banana
Nov 28, 2003

ljw1004 posted:

The intent of your proposal is so that no one writes a parameterless constructor under the belief that this will always be called, but then does something that fails to call it. It's kind of strange because library authors will have to do the {Structure, New} work at no benefit to themselves, solely to help callers. Also strange because it doesn't catch INITOBJ cases done by the caller without going via generic methods. One unknown is whether the metadata format itself can accommodate both "New" and "Structure" constraints (i.e. whether their bitfields don't clash). A bigger unknown is whether it's possible to catch all things that might call INITOBJ both directly and indirectly. That seems really hard.

you're right, the burden and benefit go in the wrong places. i'm just kind of grasping at straws here because i care more about static analysis guarantees (like: object won't exist without its constructor being called) than being able to type New SFoo() instead of SFoo.Create() :)

we've got some fairly monolithic codebases, so if {Structure,New} did become possible we'd use it internally and alleviate the issue. i understand that might not be a niche worth supporting!

Gul Banana
Nov 28, 2003

Inverness posted:

From my understanding, WPF uses MILCore at the low level to render everything with DirectX. I assume most of the work would be in making an OpenGL implementation of this for Mac and Linux. Most of the higher level stuff should work fine though, right?

Silverlight demonstrated that a XAML implementation is possible without DirectX - WinRT is more closely related to Silverlight than WPF, too, at least in terms of API subset. I don't think they'll open source either, though.

This might be somewhat uncharitable toward Microsoft, but my guess is that their .NET strategy goes something like this:
1) we own the enterprise desktop. there's nothing else as good as wpf OR forms out there, so we don't have to attract new developers to them. no major investment and keep things closed.
2) mobile is big and growing bigger, and we've got low marketshare - therefore it's a major growth opportunity. invest heavily, attempting to leverage our existing platform (which must therefore remain closed).
3) in server/cloud we're competing with other heavyweights; it's all very back and forth. a lot of people are refusing to touch asp.net because they don't Do license fees for servers or upfront IDE costs. if we get some of those people using the OWIN stack, it's a selling point for Azure, where this stuff integrates really nicely; Azure is on decent footing against the other clouds but could certainly use advantages like that.

Another example: note that the open source stuff includes WCF *client*, but not WCF *server* - that's another case where the enterprises that host WCF services have no real competition other than step down to HTTP/REST services, which falls under 3 above. Microsoft isn't interested in giving out stuff which is already a lock-in competitive advantage (this is not an attack: why *should* they be?).

There are some real benefits to openness of the stack, both to Microsoft and to Microsoft developers. Unfortunately, the first party wouldn't benefit so much in the (rather large) use case of enterprise line-of-business development. The people inside Microsoft who push for open stuff - more power to them but either they aren't interested in opening up business-desktop and internal-server stuff or, more likely, they aren't allowed because it's a different segment of the business with a different (non-growth) model.

Jewel
May 2, 2009

ljw1004 posted:

For VB/C#, here are complete lists of all new language features in C#6 and VB14.

Hey I just thought of a feature I'm interested in, relating to null propagation. I'd like the same ideal to be applied to function calls, or potentially just events? I hate having to check if an event is null every time, and I'd much rather someEvent?() or similar syntax!

Jewel fucked around with this message at 08:07 on Nov 15, 2014

twodot
Aug 7, 2005

You are objectively correct that this person is dumb and has said dumb things

Inverness posted:

I meant, Forms, WPF, and the whole Desktop CLR. :unsmigghh:

How does WPF factor into it? The lack of cross-platform WPF is the reason I can't swear off WinForms. Mono has WinForms wrap GTK+ or whatever on other platforms, so that is cross platform as much as a native GUI wrapper can be.

From my understanding, WPF uses MILCore at the low level to render everything with DirectX. I assume most of the work would be in making an OpenGL implementation of this for Mac and Linux. Most of the higher level stuff should work fine though, right?
I don't know anything about WPF, but the Desktop CLR and the stuff that sits on top of it (like WPF) are different things, so even if we did cross platform Desktop, you still probably wouldn't get WPF. Getting WPF to look like it fits in in other platforms is probably impossible for Microsoft to do, so even if it happened, I'm guessing it would look terrible. The cross platform effort is really directed at ASP.NET vNext and Azure which doesn't suffer the UI problem, and can run on .NET Core.

bpower
Feb 19, 2011
I'm trying to use .net MVC with Entity Framework code first to an existing MYSQL database. I'm just trying to set it up at the moment. I can create my EF classes but when I try to create a controller I get...


---------------------------
Microsoft Visual Studio
---------------------------
Error

There was an error running the selected code generator:

'Unable to retrieve metadata for 'proto_15Nov_2.Models.bs_business'. Sequence contains no matching element'
---------------------------
OK
---------------------------



I can access the dbcontext with

code:
            using (var db = new Models.accounts())
            {
                var query = from b in db.bt_batch
                            select b;

                foreach (var batch in query)
                {
                    Debug.Print("File Name : " + batch.bt_filename);
                }
            }
I'm using all the latest everything, vs 2013, mysql connector 6.9.4. etc.


When I try the simple steps here

https://blogs.oracle.com/MySqlOnWindows/entry/howto_using_mysql_for_visual

I get this error at the end of the wizard.

---------------------------
Microsoft Visual Studio
---------------------------
Error HRESULT E_FAIL has been returned from a call to a COM component.
---------------------------
OK
---------------------------

I've tried all the techniques found when you google ".net mvc mysql entity framework", but nothing works. Is Entity Framework and MySQL always going to be a flaky match or do I just need to learn a poo poo load more? Im thinking of moving to SQL Server instead, is it just a matter of finding a host that provides it? Theres no other cost involved?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

bpower posted:

Is Entity Framework and MySQL always going to be a flaky match....

Almost assuredly, yes.

bpower
Feb 19, 2011

Bognar posted:

Almost assuredly, yes.

Whats the recommended way to connect to mySQL in .net mvc? I don't fancy writing a poo poo load of boring data access code.

I can move to MSSQL but there'll be a bit of resistance.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

bpower posted:

Whats the recommended way to connect to mySQL in .net mvc? I don't fancy writing a poo poo load of boring data access code.

I can move to MSSQL but there'll be a bit of resistance.
I've never accessed mySQL via .net, but which is the path of least resistance? Writing boring data access code, dealing with the Entity and mySQL issues, or moving to MSSQL?

bpower
Feb 19, 2011

Uziel posted:

I've never accessed mySQL via .net, but which is the path of least resistance? Writing boring data access code, dealing with the Entity and mySQL issues, or moving to MSSQL?

Welp, I guess we're moving to MSSQL.

ljw1004
Jan 18, 2005

rum

Jewel posted:

Hey I just thought of a feature I'm interested in, relating to null propagation. I'd like the same ideal to be applied to function calls, or potentially just events? I hate having to check if an event is null every time, and I'd much rather someEvent?() or similar syntax!



Note: although the ?. operator is built into C#6 and VB14, the warning squiggle and codefix in this video are not built in. I wrote them myself via a simple "analyzer" - I put the source code here on github. For me the single most important feature of VS2015 is that you can write your own refactorings, analyzers and code-fixes.


PS. VB14 has the syntax "PropertyChanged?(args)" that you suggested but C#6 doesn't. That's because it would be ambiguous in C# with the ternary operator "b ? (args) : elseclause"...

Forgall
Oct 16, 2012

by Azathoth
PropertyChanged?.Invoke is a very neat syntax, and I'm glad you've made it easy to add your own refactorings. Wonder if that'll cut into resharper sales.

raminasi
Jan 25, 2005

a last drink with no ice
While we're on the subject, is there some reason that the strategy of avoiding null-checking PropertyChanged via assigning a no-op delegate on construction hasn't gotten more traction? Is there some serious penalty to it that I'm unaware of?

Inverness
Feb 4, 2009

Fully configurable personal assistant.

GrumpyDoctor posted:

While we're on the subject, is there some reason that the strategy of avoiding null-checking PropertyChanged via assigning a no-op delegate on construction hasn't gotten more traction? Is there some serious penalty to it that I'm unaware of?
Allocating delegates, from what I assume is a lambda expression, has a memory cost. Even if it's relatively small you'd still be allocating an extra object per event per instance which both wastes memory and puts pressure on the GC.

Of course in most cases the compiler will cache the allocation of lambdas that don't capture variables. Even then you're basically relying on compiler optimizations to not totally waste memory which I consider bad practice.

You could avoid that by declaring static variables for each event type to hold the no-op delegates for each, but then that seems like more effort than just doing the null check.

Finally, use a method to handle the null check, but that is only really useful for generic event delegates and prevents you from being able to only allocate EventArgs if the null check passes. For an event invoked frequently this is wasteful if there are no handlers.

TL;DR: Manual null check is more boilerplate but it avoids memory wastes or gotchas that can crop up with other approaches.

Edit: This made me realize an important question. If I do MyEvent?.Invoke(new MyArgs()), then do the args only get allocated if MyEvent is not null?

Inverness fucked around with this message at 20:24 on Nov 16, 2014

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

GrumpyDoctor posted:

While we're on the subject, is there some reason that the strategy of avoiding null-checking PropertyChanged via assigning a no-op delegate on construction hasn't gotten more traction? Is there some serious penalty to it that I'm unaware of?

It's minutely slower. I always initialize my events as "public event EventHandler OnButtz = delegate { };". Harder to get snagged on event related rough edges.

epswing
Nov 4, 2003

Soiled Meat
I just ran Visual Studio Ultimate 2013 Update 4, and VS is now barfing up a bunch of errors



The ActivityLog.xml shows this: http://pastebin.com/pPGdsm1P

Excerpt:
pre:
Loading MEF components failed with the following exception: 
The composition produced a single composition error. The root cause is provided below.
Review the CompositionException.Errors property for more detailed information.

1) The specified argument cannot be empty.
Parameter name: commandContainers

Resulting in: An exception occurred while trying to create an instance of type 
'Microsoft.VisualStudio.TestWindow.VsHost.PackageContainer'.
Any idea what's happening here? Googling yields an old MS Connect article closed as "Can't Reproduce" and not much else.

bpower
Feb 19, 2011

epalm posted:

I just ran Visual Studio Ultimate 2013 Update 4, and VS is now barfing up a bunch of errors



The ActivityLog.xml shows this: http://pastebin.com/pPGdsm1P

Excerpt:
pre:
Loading MEF components failed with the following exception: 
The composition produced a single composition error. The root cause is provided below.
Review the CompositionException.Errors property for more detailed information.

1) The specified argument cannot be empty.
Parameter name: commandContainers

Resulting in: An exception occurred while trying to create an instance of type 
'Microsoft.VisualStudio.TestWindow.VsHost.PackageContainer'.
Any idea what's happening here? Googling yields an old MS Connect article closed as "Can't Reproduce" and not much else.

I've been clicking past that for a few weeks. Its some nonsense about the IDE writing to a log. It looks fairly harmless, but annoying for sure.

Mr. Crow
May 22, 2008

Snap City mayor for life

Inverness posted:

Allocating delegates, from what I assume is a lambda expression, has a memory cost. Even if it's relatively small you'd still be allocating an extra object per event per instance which both wastes memory and puts pressure on the GC.

Of course in most cases the compiler will cache the allocation of lambdas that don't capture variables. Even then you're basically relying on compiler optimizations to not totally waste memory which I consider bad practice.

You could avoid that by declaring static variables for each event type to hold the no-op delegates for each, but then that seems like more effort than just doing the null check.

Finally, use a method to handle the null check, but that is only really useful for generic event delegates and prevents you from being able to only allocate EventArgs if the null check passes. For an event invoked frequently this is wasteful if there are no handlers.

TL;DR: Manual null check is more boilerplate but it avoids memory wastes or gotchas that can crop up with other approaches.

Edit: This made me realize an important question. If I do MyEvent?.Invoke(new MyArgs()), then do the args only get allocated if MyEvent is not null?

In the world of dumb micro-optimizations this is probably up there.

However the annoyance of null checking events everywhere can be circumvented (along with boilerplate event-raising logic) with a simple extension method. This also satisfies the 'performance' inclined as well, and in my opinion is just easier to use/read.
code:
public static void Raise(this EventHandler handler, object sender, EventArgs e)
{
    if (handler != null)
    {
        handler(sender, e);
    }       
}
code:
Butts.Raise(this, new ButtsArg());
I think you end up making a total of like 6 overloads for the various event handler types that don't derive from EventHandler, for example NotifyCollectionChangedEventHandler.

Mr. Crow fucked around with this message at 15:48 on Nov 17, 2014

epswing
Nov 4, 2003

Soiled Meat

bpower posted:

I've been clicking past that for a few weeks. Its some nonsense about the IDE writing to a log. It looks fairly harmless, but annoying for sure.

I cannot open the Test Explorer window, so for me it's more than just writing to log files :smith:

brap
Aug 23, 2004

Grimey Drawer

Mr. Crow posted:

In the world of dumb micro-optimizations this is probably up there.

However the annoyance of null checking events everywhere can be circumvented (along with boilerplate event-raising logic) with a simple extension method. This also satisfies the 'performance' inclined as well, and in my opinion is just easier to use/read.
code:
public static void Raise(this EventHandler handler, object sender, EventArgs e)
{
    if (handler != null)
    {
        handler(sender, e);
    }       
}
code:
Butts.Raise(this, new ButtsArg());
I think you end up making a total of like 6 overloads for the various event handler types that don't derive from EventHandler, for example NotifyCollectionChangedEventHandler.

There's a method written at my workplace of this nature:

code:
public static T2 GetValue(this T1 t1, Func<T1, T2> transform) {
    if (t1 == null) { return null; }
    return transform(t1);
}

Person foo = nil;
foo.GetValue(p => p.Name);
// doesn't crash
However I cannot wait for this all to be forgotten by time and simply replaced by ?. All of these methods that wrap up null checks are currently necessary ugly poo poo.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Quick rant: Microsoft keeps adding features to the DSC-based release management option, which would be great if the DSC-based option was even remotely loving usable right now. They're ignoring every single existing user of the product, none of which are using DSC.

EssOEss
Oct 23, 2006
128-bit approved
I know it's poo poo but is there even any good alternative to that? For some nontrivial solution, I mean, such as including Windows services, IIS apps, DCOM fuckery and more. All my current experience says "hell no". At the moment, I am planning the deployment process for a new project and am strongly considering just making an Install.exe console app to take care of the whole thing in a way that I know will do the job.

Sedro
Dec 31, 2008

Mr. Crow posted:

In the world of dumb micro-optimizations this is probably up there.

However the annoyance of null checking events everywhere can be circumvented (along with boilerplate event-raising logic) with a simple extension method. This also satisfies the 'performance' inclined as well, and in my opinion is just easier to use/read.
code:
public static void Raise(this EventHandler handler, object sender, EventArgs e)
{
    if (handler != null)
    {
        handler(sender, e);
    }       
}
code:
Butts.Raise(this, new ButtsArg());
I think you end up making a total of like 6 overloads for the various event handler types that don't derive from EventHandler, for example NotifyCollectionChangedEventHandler.

But now you're constructing the EventArgs even if you don't fire the event! You could pass them as Func<EventArgs> but now you're constructing delegates, which was the "problem" we were originally trying to avoid.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

Sedro posted:

But now you're constructing the EventArgs even if you don't fire the event! You could pass them as Func<EventArgs> but now you're constructing delegates, which was the "problem" we were originally trying to avoid.
Whether this is actually a problem depends on what kind of application you're writing. For most GUI apps, constructing some delegates or event args that wont be used will not have a real impact on performance.

If you're making a game or something, the last thing you want to do is allocate objects you don't need, which is why I do null checks and avoid allocating until after the check passes. That habit remains even when I write other things.

Mr. Crow
May 22, 2008

Snap City mayor for life

Inverness posted:

Whether this is actually a problem depends on what kind of application you're writing. For most GUI apps, constructing some delegates or event args that wont be used will not have a real impact on performance.

If you're making a game or something, the last thing you want to do is allocate objects you don't need, which is why I do null checks and avoid allocating until after the check passes. That habit remains even when I write other things.

Well your first mistake was writing a game in .NET :rimshot:

xgalaxy
Jan 27, 2004
i write code

Mr. Crow posted:

Well your first mistake was writing a game in .NET :rimshot:

99.9999999% of indie games won't see a difference between C# and C++ performance wise.*
With .NET Native I suspect there is very little reason to use C++ for hobby / indie game dev outside of learning experience.





*= assuming it is competently written.

xgalaxy fucked around with this message at 01:48 on Nov 18, 2014

Inverness
Feb 4, 2009

Fully configurable personal assistant.

Mr. Crow posted:

Well your first mistake was writing a game in .NET :rimshot:
This makes me feel like you don't know enough about either C# or gamedev :colbert:

C# is just fine for the vast majority of games out there. I've had zero performance problems.

xgalaxy posted:

*= assuming it is competently written.
This. When it comes to both C++ and C# it's pretty easy to gently caress yourself over.

Just take the latest version of Minecraft for example. Ignoring that Java has no value types, some genius behind that didn't realize that it would be a bad idea to use things like immutable types and temporary objects everywhere. That game now allocates 50 MB per second with its latest version which has tanked performance for many people. It's a good example of how design patterns are circumstantial (and Java is bad).

Inverness fucked around with this message at 01:56 on Nov 18, 2014

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
After finding a bug with a lambda expression in one of MS's code examples, I did some googling to actually teach myself about them. I want to make sure that I actually understand them. Are C#'s lambda expressions really just anonymous functions?

For example, if my understanding is right, this code:
C# code:
int x = 2;
Console.Write(x => x*x);
would just print the number 4 to the console? It's just to write quickie one-off computations that might be called in one particular loop and so not warrant their own full-blown function?

edit: Trying this out in visual studio, it clearly doesn't work. I'm not sure why, though. All the examples I can find using primitive types assign the function to a variable first and then basically call it like any other function. That seems semi-pointless to me. How can I write inline lambdas using primitives?

The MUMPSorceress fucked around with this message at 06:47 on Nov 18, 2014

raminasi
Jan 25, 2005

a last drink with no ice

LeftistMuslimObama posted:

After finding a bug with a lambda expression in one of MS's code examples, I did some googling to actually teach myself about them. I want to make sure that I actually understand them. Are C#'s lambda expressions really just anonymous functions?

For example, if my understanding is right, this code:
C# code:
int x = 2;
Console.Write(x => x*x);
would just print the number 4 to the console? It's just to write quickie one-off computations that might be called in one particular loop and so not warrant their own full-blown function?

edit: Trying this out in visual studio, it clearly doesn't work. I'm not sure why, though. All the examples I can find using primitive types assign the function to a variable first and then basically call it like any other function. That seems semi-pointless to me. How can I write inline lambdas using primitives?

Console.Write doesn't have an overload that takes a delegate, so I'm not sure why you think that code would work. What you're doing there would basically be right if you actually called an appropriate method. You see lambdas a lot with LINQ:
C# code:
IEnumerable<int> DoubleEverything(IEnumerable<int> input)
{
    return input.Select(x => x * 2);
}
I think the reason you're seeing tutorials that assign the lambdas to variables instead of letting them be temporary is so that you learn how they're typed, although apparently that plan failed.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

GrumpyDoctor posted:

Console.Write doesn't have an overload that takes a delegate, so I'm not sure why you think that code would work. What you're doing there would basically be right if you actually called an appropriate method. You see lambdas a lot with LINQ:
C# code:
IEnumerable<int> DoubleEverything(IEnumerable<int> input)
{
    return input.Select(x => x * 2);
}
I think the reason you're seeing tutorials that assign the lambdas to variables instead of letting them be temporary is so that you learn how they're typed, although apparently that plan failed.

I think the tutorials assumed I already knew alot about anonymous functions. Can you point me to a guide that will help me uses lambda expressions effectively?

Funking Giblet
Jun 28, 2004

Jiglightful!
You seem to be thinking of them wrong.


Imagine I said that I wanted a function to multiply a number by 2.

code:
public int Multiply(int input)
{    
    return input * 2;
}
You could write this using a lambda syntax of f(x) = 2x.
Which is basically a function which operates on x which returns 2*x, or as in our case above

f(input) = 2input.

A lambda in C# would be the same as the above, the input variable is returned as 2 * input

input => 2 * input

Most people just write

x => 2 * x.

"With x as an input, return 2 * x"

What you are probably thinking then, is why didn't Console.Write work with my lambda function.

Well, a lamba is an anonymous function definition, it doesn't actually call (unless you explicitly do so). Passing it to Console.Write, you could expect Console.Write to call the function in it's body and pass it's own x, but as Console.Write doesn't take a delegate as an overload, this isn't possible. The way you declared x as an int didn't make sense in this context. Think of it this way instead.

code:
//Func<int,int> is just a way to assign a lambda delegate to a variable, the <int,int> it takes an int, and returns an int, I would ignore it for now.
Func<int,int> myLambda = x => 2 * x;

var result1 = myLambda(2);
var result2 = myLambda(3);

//Result1 = 4;
//Result2 = 6

myLambda is just a definition of a function, you can pass it your variables later.

ljw1004
Jan 18, 2005

rum

Sedro posted:

But now you're constructing the EventArgs even if you don't fire the event!

One idea:


(source code for this VS2015 analyzer is here)

Gul Banana
Nov 28, 2003

Those one-off analysers are pretty convincing ads for vs2015! Can they be shared with a team via e.g. extension galleries?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
ReSharper is in trouble when VS2015 comes out. They're going to continue rolling their own static analysis tools and totally ignore Roslyn.

[edit]
I like that the null propagation operator is called the "Elvis" operator. Adorable.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

ljw1004 posted:

One idea:


(source code for this VS2015 analyzer is here)
I think that's an interesting concept but would require you to have one of those for each name. I think CallerMemberNameAttribute is more useful in a case like this anyways.

This is the pattern I use in a MVVM application:
code:
public abstract class ViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
    {
        if (EqualityComparer<T>.Default.Equals(field, value))
            return false;
        field = value;
        OnPropertyChanged(propertyName);
        return true;
    }

    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName));
    }
}

// And in a subclass:

public abstract class DockingItemViewModel : ViewModel
{
    private string _title;
    private string _description;
    private ImageSource _imageSource;

    public string Title
    {
        get { return _title; }

        set { SetProperty(ref _title, value); }
    }

    public string Description
    {
        get { return _description; }

        set { SetProperty(ref _description, value); }
    }

    public ImageSource ImageSource
    {
        get { return _imageSource; }

        set { SetProperty(ref _imageSource, value); }
    }
}

Ithaqua posted:

ReSharper is in trouble when VS2015 comes out. They're going to continue rolling their own static analysis tools and totally ignore Roslyn.
Why do you think they'd be in trouble?

I remember them commenting on Roslyn and saying that it's basically what they do internally anyways. They can hardly afford to abandon or rewrite all of the code centered around their own methods.

Chill Callahan
Nov 14, 2012
Here's the blog post by the way if anyone cares: http://blog.jetbrains.com/dotnet/2014/04/10/resharper-and-roslyn-qa/

Mr. Crow
May 22, 2008

Snap City mayor for life

Inverness posted:

I think that's an interesting concept but would require you to have one of those for each name. I think CallerMemberNameAttribute is more useful in a case like this anyways.

This is the pattern I use in a MVVM application:
code:
public abstract class ViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
    {
        if (EqualityComparer<T>.Default.Equals(field, value))
            return false;
        field = value;
        OnPropertyChanged(propertyName);
        return true;
    }

    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName));
    }
}

// And in a subclass:

public abstract class DockingItemViewModel : ViewModel
{
    private string _title;
    private string _description;
    private ImageSource _imageSource;

    public string Title
    {
        get { return _title; }

        set { SetProperty(ref _title, value); }
    }

    public string Description
    {
        get { return _description; }

        set { SetProperty(ref _description, value); }
    }

    public ImageSource ImageSource
    {
        get { return _imageSource; }

        set { SetProperty(ref _imageSource, value); }
    }
}
Why do you think they'd be in trouble?

I remember them commenting on Roslyn and saying that it's basically what they do internally anyways. They can hardly afford to abandon or rewrite all of the code centered around their own methods.

@ReSharper, agreed. At best I think they're going to finally have competition in the form of open source refactorings; which means they'll have to step up their game (which is a good thing for consumers/developers). I would expect we'll see one or a couple big open source refactoring/inspection/code-quality projects come out that utilize Roslyn and become defacto Visual Studio 'plugins' for those that don't want to pay for something of a higher quality, better integration etc.


One thing I am curious on, I would be curious on the performance of similar competing projects vs ReSharper. (I haven't payed much attention to Roslyn at all) I wonder if Roslyn-based project will outperform ReSharper on large projects.

Adbot
ADBOT LOVES YOU

Inverness
Feb 4, 2009

Fully configurable personal assistant.
Will Roslyn let me add code at compile-time like PostSharp does?

That would be fantastic.

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