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.
 
  • Locked thread
RICHUNCLEPENNYBAGS
Dec 21, 2010

I've wondered about this for a while. Is this genuinely useable for a real project or is it just a toy? I mostly use C# at work but I have a Mac at home; it'd probably be easier to get myself writing more C# if I had the motivation of being able to use what I'm writing at home.

Adbot
ADBOT LOVES YOU

RICHUNCLEPENNYBAGS
Dec 21, 2010
Since there's all this talk about modules, in practice what makes a static class so different from a module?

I've worked with C# and VBA so I can pretty much understand VB.Net but I haven't used it for anything really

RICHUNCLEPENNYBAGS fucked around with this message at 00:25 on Jun 21, 2013

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ithaqua posted:

http://stackoverflow.com/questions/881570/classes-vs-modules-in-vb-net

Extension methods have to be in modules, apparently, among other things.

Well, if I'm reading this right, basically modules are static classes.

RICHUNCLEPENNYBAGS
Dec 21, 2010

edmund745 posted:

There seems to be accounts of before Microsoft allowed TFS Express to work with VS Express--and also accounts of after, when they did. And the TFS Express use terms don't clear much up.
Not that it matters much, it's all indecipherable.

I've spent the last day or so searching Google for "single user version source control", and people say the best choice is,,,,, everything. Everyone says everything is great for some reason. I understand what it's supposed to do, but everything I've seen so far is way too much work to learn to use, for one person working only on one PC.

I'd want something more like PC file-backup software: no network bothers, no multiple-user capability, no branching or merging cause I'd never use it. Just save a set of files as a series of revisions, and go forwards or backwards.... I want something I can set up and be using in ~15 minutes. It looks like if I really wanted it, I'd have to write it myself though. :\

The source-control-software ability to visually compare file versions is nice, but I can live without it.

OK, so, make a mercurial repo and store it on Dropbox or something. You need to know like three commands to do what you want and they're all here: http://hginit.com/01.html

RICHUNCLEPENNYBAGS
Dec 21, 2010

lovely Treat posted:

I need to convert a small VB6 app to VB.net is there any software that can convert it semi reliably so I only need to fix a few things or will it be a complete mess and I'm better off starting over from scratch?

Even if there were such a tool (I don't think this is), the output would not in any way resemble best-practice VB.Net code.

RICHUNCLEPENNYBAGS
Dec 21, 2010
Is there a decent reference I could refer to understand like, enough of C++ that I can read documentation on Win32 stuff and understand it well enough to work with it in C#? I mean in particular I have trouble understanding what all the data types for arguments to functions are supposed to be.

RICHUNCLEPENNYBAGS
Dec 21, 2010

GrumpyDoctor posted:

If you're trying to wrap your head around P/Invoke stuff, the piece you're missing isn't C++ knowledge. P/Invoke is just a pain. Maybe give something like this a shot?

Otherwise I don't understand your question.

Like look at this: http://msdn.microsoft.com/en-us/library/windows/desktop/bb530498(v=vs.85).aspx

I don't really know what HWND, LPCWSTR, or DWORD are supposed to be and I feel like I'd probably understand it better if I had some basic knowledge of Windows C++ programming? I mean you can look these things up one-by-one I guess, but that's a pain and leads to a really shallow understanding.

RICHUNCLEPENNYBAGS
Dec 21, 2010
I asked this question in the Excel thread, but maybe it would be better here. Is there a book or resource you folks recommend for VSTO? I'm not starting from zero because I have spent a fair amount of time with VBA so I have some appreciation for the Word/Excel object models but I'd like to be able to make real add-ins.

RICHUNCLEPENNYBAGS
Dec 21, 2010

thezoidburg posted:

You may know this already, but since its the .Net thread, don't forget you can write add-ins in JavaScript and HTML now so they can run on both local office and web versions. I don't know exactly what platforms these add-ins can target however (new ipad apps too?)

I'm aware of this, but from the sound of it it's way more limited than VBA (except that you can talk to Web services, which is cool I guess but I don't know what I'd do with that).

RICHUNCLEPENNYBAGS
Dec 21, 2010
OK, so, I'm just going to go ahead and ask this even though I think it's probably a stupid question.

I'm trying to start getting into unit tests. I haven't ever really used them before. I'm working on an MVC project with data being persisted with EF CodeFirst (it's a week old so there aren't mountains of legacy stuff or anything).

So it seems like the preferred way of doing this is creating an interface, then having my data store implement that interface, so that I can also have a pretend repository implementing it that I'll use in my tests. I mean, OK, I get that in theory, but how does this work in the real world without me totally reimplementing all the canned stuff I'm getting with the ApplicationDbContext and the various methods UserManager is offering to do user-related stuff (using ASP.Net identity instead of handrolled stuff)? Most of the examples I see are talking about rolling your own, which makes the concept easy to understand but I'm not seeing how it's supposed to work in an actual project instead of just something that's a toy.

I realize there are huge books on this subject but I'm also learning Entity and MVC through this project so I'm not too keen on reading a big tome just on DI or unit testing; I'd like some material that I could basically look at in one sitting. Also, while there are probably valid reasons not to use some of the canned stuff I'm talking about the project I'm working on is on a tight schedule where being able to use premade stuff is a big help.

edit: In case this is like total gibberish I'm talking about starting with the MVC project type that already has identities and login/registration all built in out of the box.

RICHUNCLEPENNYBAGS fucked around with this message at 05:30 on Dec 28, 2013

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ithaqua posted:

The role/membership provider uses a lot of static classes, which makes life trickier. Encapsulate all of the membership provider stuff up in a class and then inject an implementation of that class to your controllers. Then you can mock the data it returns.

So you mean I should just create another class that's going to wrap all the UserManager methods?

RICHUNCLEPENNYBAGS
Dec 21, 2010
I mean... am I really making that better by building another class that's just going to call those methods? I'm missing something here.

RICHUNCLEPENNYBAGS
Dec 21, 2010
OK, I think I'm following now.

So if I can go ahead and ask a dumb follow-up question: that seems pretty straightforward. What's the advantage of using a whole DI framework?

RICHUNCLEPENNYBAGS
Dec 21, 2010
MVC question: If I put a DbContext in the constructor of a controller, what is the lifecycle? Will it be disposed of when a request is handled? Does it cause concurrency issues?

RICHUNCLEPENNYBAGS
Dec 21, 2010
The specific use I have in mind is instantiating a new instance DbContext in the constructor and then disposing of it in the controller's Dispose method.

RICHUNCLEPENNYBAGS fucked around with this message at 00:18 on Jan 1, 2014

RICHUNCLEPENNYBAGS
Dec 21, 2010
I get why you're saying that but I just wanted to know if the controller's Dispose was going to happen with every request.

RICHUNCLEPENNYBAGS
Dec 21, 2010
Why not have a disposable data access class instead of wrapping every single method in using?

RICHUNCLEPENNYBAGS
Dec 21, 2010
Right, but why should the lifespan be so different if it's getting disposed after every request? I'm not talking about a static connection or anything.

e: This is a genuine question; I hope I'm not giving you the impression I'm challenging you because you obviously have more experience with MVC than I do.

RICHUNCLEPENNYBAGS fucked around with this message at 05:12 on Jan 3, 2014

RICHUNCLEPENNYBAGS
Dec 21, 2010

Che Delilas posted:

It's not necessarily bad on a technical level (that I know of), though I'm sure there are some corner cases where it won't get disposed the way you expect. It's more a design issue. Spraying data access logic at your Controller classes severely breaks separation of concerns, which is the point of MVC to begin with. Data access is such an orthogonal issue to an MVC app that it really should be handled in its own place; at minimum in its own class (some projects have it in its own project entirely). And really, moving each linq query out to its own method in a data access class somewhere doesn't really add a lot of complexity at all, if you don't bother with doing full dependency injection.

It's a shame that every beginners guide and tutorial does it precisely the wrong way (dbcontext instantiated directly in the controller), in their haste to explain Actions and passing data through to strongly typed Views. I get why they do it, it just does damage to new developers and it's something you have to unlearn when you start doing big projects.

I understand that, but what if you have a separate class that, say, has methods like GetMyObject() or SaveApplicationObject() or whatever, rather than directly making DbContext calls, and that class is itself disposable? Then you can dispose it in the controller's dispose method and if you're using an interface you could go back and mock it later (yeah it should probably happen at the same time but I'm working on a really tight deadline to have a first release).

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ithaqua posted:

I saw a great presentation by Dustin Campbell from Microsoft last week. He talked about the future of C# and mentioned some cool stuff they have planned for C# 6.

I found a blog post by someone who paid attention at a similar talk and took good notes, which I didn't.

This is all great. I'm glad to see them moving in a direction that is gradually reducing boilerplate you have to write.

RICHUNCLEPENNYBAGS
Dec 21, 2010
You know, as useful as ReSharper is sometimes I wonder about the suggestions. Some of the Linq query replacements for loops are kind of difficult to read.

I mean, not so difficult you can't look and figure out but that's a distraction.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Dietrich posted:

I personally despise the from whatever select x, y syntax for using linq, and stick with the whatever.select(w => new { w.x, w.y}); syntax, but maybe it's just me. Either way a lot of the time resharper makes good suggestions more than a majority of the time.

I agree. But it suggests them for foreach loops too and honestly sometimes it gets a little heady for my tastes.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

The things that ReSharper can generate from a foreach loop is absolutely mind-boggling. Why yes, of course I wanted this readable and understandable foreach block to be re-written with 3 SelectManys, 2 Aggregates, and a GroupJoin.
Right, yeah. This is what I meant.

Also, I guess I can configure this somehow, but I don't like how it suggests I eliminate named parameters everytime I use them. I'm using them because it's confusing without them! Come on.

Also, I have ReSharper set to indent everything GNU-style, which is great, but it clashes with Visual Studio sometimes which is unfortunate. I mean I would just set VS to use GNU-style if it were an option.

RICHUNCLEPENNYBAGS
Dec 21, 2010
What kind of project only ever calls methods defined by the project itself?

Some of Microsoft's own stuff has like a billion overloads and optional arguments.

RICHUNCLEPENNYBAGS
Dec 21, 2010
That's all well and good but I think it's a little bit simplistic to say any code that is easier to read with named parameters is wrong. If that were really the case why would they have added such a feature at all?

RICHUNCLEPENNYBAGS
Dec 21, 2010
Well, fair enough, I suppose. I like to use them even when there aren't a lot of arguments. Particularly with bools because it's not obvious what you were specifying when you put "false" in something.

RICHUNCLEPENNYBAGS
Dec 21, 2010
I can't say I'm a huge fan of parameter objects either; for all the reasons you've discussed. And in any case it's hardly getting at the root of the problem (assuming it is one and you don't have a legitimate need for lots of parameters).

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

We were talking about this at work today and my co-worker convinced me that being able to return anonymous types would be a better solution. It's a bit quirky, but it allows you to have named properties instead of just relying on the position in the tuple. It might look like:

C# code:
public var GetMostUsedCharacter(string input) {
	var mostUsed = input.GroupBy(c => c).OrderByDescending(g => g.Count()).First();
	return new { Letter = mostUsed.Key, Count = mostUsed.Count() };
}
It basically gives you everything that a tuple does, but adds named properties and employs a more commonly used language feature (I rarely see Tuple<>, but anonymous types are everywhere).


I'm not sure I follow here. Isn't the point that it stops evaluating the expression once it encounters a null and thus doesn't throw NREs?

So return a dynamic then.

I mean I know people are afraid of them but they're useful for any number of things.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

I honestly wish dynamics had never been added. I get that they're useful for making COM interop code not look terrible, but I feel like the solution is to build a sane wrapper API around common COM interaction rather than adding duck typing to a statically typed language. I don't have a problem with duck typing in and of itself, I just don't want it littered throughout my statically typed code. The compiler will check my errors in all my statically typed code, but the compiler only looks like it's checking my errors in dynamically typed code.

Dynamic dispatch is a really useful idiom, anyway. I don't think anonymous types are really all that much "better" than dynamics in any of the aspects that bother you about dynamics.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

Except that anonymous types offer compile time type safety.

I just don't see what kind of sense it makes returning them. If you think you're going to need the object in multiple places you should actually define it. Otherwise it seems to me you're getting an inappropriate level of coupling between methods.

As for type safety, if you want you can cast a dynamic to get Intellisense or whatever. But to be honest I think the chances of this kind of error aren't super-high and also they're going to be really obvious when you run across them.

RICHUNCLEPENNYBAGS fucked around with this message at 17:54 on Jan 19, 2014

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ender.uNF posted:

You are coupled to the method by definition. If I change the return type from byte[] to int, bool to float, or Frobber to Gobulator you're just as tightly coupled as if I were returning { x, y }. If I change the parameter list, other than adding new optional parameters or some limited type changes, all my callers must be updated. If I add, remove, or change out/ref parameters I just broke your poo poo yo.

Same would apply to returning an anonymous type: anything other than adding new properties is a breaking change. Yes, a class must be defined... But let the compiler worry about it.

You can certainly create iterators without yield return but why the hell would you? Let the compiler create that class for you.


"you should define it" automatically smells like bullshit to me because you can apply that argument to everything besides pure assembly. No, actually, I shouldn't have to define it when the compiler can figure it out automatically.

Except now instead of reading a class definition to find out the properties of an object, you're going and reading through a method. This isn't really good design.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

Sure, when you run across them at runtime as opposed to never having the problem at all because the compiler handled it all for you. I don't understand why you would willingly throw away the compiler's error checking when it's basically free.

EDIT:

Here's some example code:

C# code:
// Anonymous type return value
public var GetMostUsedCharacterAnonymousType(string input) {
	var mostUsed = input.GroupBy(c => c).OrderByDescending(g => g.Count()).First();
	return new { Letter = mostUsed.Key, Count = mostUsed.Count() };
}

public void CompilerError(){
	var mostUsed = GetMostUsedCharacterAnonymousType("testtest");
	Console.WriteLine("{0}: {1}", mostUsed.Letter, mostUsed.Coutn);
}

// Dynamic type return value
public dynamic GetMostUsedCharacterDynamic(string input) {
	var mostUsed = input.GroupBy(c => c).OrderByDescending(g => g.Count()).First();
	return new ExpandoObject { Letter = mostUsed.Key, Count = mostUsed.Count() };
}

public void RuntimeError(){
	var mostUsed = GetMostUsedCharacterDynamic("testtest");
	Console.WriteLine("{0}: {1}", mostUsed.Letter, mostUsed.Coutn);
}
The code is almost exactly the same, yet one fails as soon as you press F5. Why would I pick the other?

Yeah, great, but this is so trivial that I don't think it's worth worrying about. Using dynamics can save you from writing a lot of extraneous code.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

I don't disagree that dynamics have their place, I just don't think that place is to deal with multiple return values when you could use tuples, anonymous types :smith:, or concrete classes instead.

Well, I probably wouldn't use them for your use case, but like I said, I have a philosophical objection to the idea of returning an anonymous object.

I just think it's unfortunate that there are so many folks in the C# community who have a pathological aversion to any technique requiring some care when being used.

RICHUNCLEPENNYBAGS
Dec 21, 2010

SweetKarma posted:

Is there any reason I shouldn't learn VB as my first .NET language? C# seems to be the more popular language at the moment and it makes me wonder if I should learn it instead of VB since there will be more learning resources. Frankly my only reason for learning VB is that I'm burnt out on C-style syntax.

There is close to zero difference in capabilities but C# developers tend to earn more on average if that is important to you.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Dietrich posted:

My intention was to demonstrate the difference in verbosity between VB and C# when using generics and lambda expressions, not to write the shortest code in either language.

Personally, (Of T, T2, T3) bugs the poo poo out of me, especially with nested generics, and a lot of fluent language APIs look especially bad in VB compared to C#. (Map<Class>.To("TableName") versus Map(Of Class).To("TableName");)

Function(x)/Sub(x) is much more annoying to write than x =>

And End Sub / End Function is much more annoying to write than }

Not that I don't have a great deal of respect for what you've accomplished in VB.Net, ljw1004

I don't think verbosity si a big deal with .NET languages because of Intellisense. Certainly C# itself is quite verbose compared to some other popular languages and typical style also uses variable names that are, comparatively, long.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ithaqua posted:

First off, answer this question: Why do you want to use Git over standard TFVC? Git is generally a lot harder to use effectively. Full disclosure: I am massively biased against Git.

How do you figure?

RICHUNCLEPENNYBAGS
Dec 21, 2010

2banks1swap.avi posted:

We did once! But now we don't. Not sure why.

That's something I need to ask.

I think that was meant to be a suggestion, rather than a question.

RICHUNCLEPENNYBAGS
Dec 21, 2010
This is more curiosity than anything else, but do any of you have any of the C# certifications MS puts out? Is there any reason to be interested if you're already a working developer?

RICHUNCLEPENNYBAGS
Dec 21, 2010

wwb posted:

I haven't spent any measurable time with the new identiy framework though it looks good and I don't see why you couldn't easily roll your own plumbing for the raw ADO.NET bits.

I have; the current project we're working on uses it because we were time-constrained.

You get users, hashed passwords, roles, and claims, which is nice. But there are some weird things (like you don't have to have a password for an account) and you're going to end up doing some stuff on your own unless you don't need to have password reset or changing usernames or a couple other features.

I think it would be miserable or at least pointless if you aren't using EF though.

Adbot
ADBOT LOVES YOU

RICHUNCLEPENNYBAGS
Dec 21, 2010
To use EF and not end up with an unmaintainable mess you have to know how databases work and what EF is doing under the hood so I don't think you're going to remove the need for them to understand SQL entirely (even if you don't care how it ends up you need to have relationships on your objects going both ways to get cascading delete under certain circumstances and if you don't bother to do that you'll just get EF errors when you try to delete stuff which are gonna be a pain).

I don't know much about the performance characteristics if you have crazy scale. My project doesn't have gazillions of users. I don't notice the overhead.

But anyway, my point is I would recommend it for people who already know SQL but don't want to bother hand-mapping everything, not people who don't know anything about SQL and are hoping to avoid learning. I'm using Code First though; I guess some of these things might play out differently with DB First.

RICHUNCLEPENNYBAGS fucked around with this message at 01:35 on Feb 28, 2014

  • Locked thread