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
brap
Aug 23, 2004

Grimey Drawer
I wish the REPL for F# was as good as one for a scripting language or even as good as the immediate window for C#. I found it to be a struggle.

brap fucked around with this message at 03:29 on Oct 26, 2014

Adbot
ADBOT LOVES YOU

brap
Aug 23, 2004

Grimey Drawer
You can get the types of generic arguments via reflection, but I too wonder if there's a better way to do what you're doing.

brap
Aug 23, 2004

Grimey Drawer
Most of the badness to do with global variables has to do with the fact that they are variables. If you want to bind an immutable value to a name to reference it from any function, there's nothing wrong with that.

brap
Aug 23, 2004

Grimey Drawer
Honestly I'm mostly just interested in seeing the good parts of F# make it to C#-- pattern matching, discriminated unions and all that jazz.

brap
Aug 23, 2004

Grimey Drawer

Munkeymon posted:

I just wanted to drop in and mention that I just found out today that LINQPad can update the database which has inspired me to buy it because it made the most annoying part of parsing and updating a bunch of dates that SQL doesn't natively support writing C# half in VS and copying it into LINQPad. It was great to be able to slap together
code:

var re = new Regex(@"\d{1,2}\.\d{1,2}\.\d{2,4}");
string[] formats = {"M.d.yy", "MM.dd.yy", "M.dd.yy", "MM.d.yy", "M.d.yyyy", "MM.dd.yyyy", "M.dd.yyyy", "MM.d.yyyy"};

foreach(var t in Thingies.Where(t => !t.ExplosionDate.HasValue)){
	var matches = re.Matches(t.TextVomit);
	DateTime outTarget;
	if(matches.Count > 0 &&
		DateTime.TryParseExact(matches[matches.Count-1].Value, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out outTarget)){
		t.ExplosionDate = outTarget;
	}
}

SubmitChanges();

to back-fill a new column rather than figure out how to mash it together in SQL's somewhat limited text and date processing functionality or clutter up my workspace with a throwaway project.


Is everything going to be MIT or is it going to be mix-and-match? ALl I see is him saying there's already some stuff up under MIT and they want to be license agnostic somehow.


Oh hey someone remembered that WPF exists :3:

I believe that's made possible by the LINQ to SQL library straight from Microsoft. Your code is being turned into a SQL script.

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.

brap
Aug 23, 2004

Grimey Drawer
Isn't there just a general function to convert a string to html entities where necessary (i.e. use &gt; instead of >)?

brap
Aug 23, 2004

Grimey Drawer

Dietrich posted:

Any time you feel like you have to write a comment to explain your code, it means you need to re-write your code.

(Or you're doing something that makes absolutely no logical sense because there's a framework bug you have to deal with or something)

Overcommenting is terrible, and a code style that "documents" itself well is important, but it's too much to say that good code never warrants comments.

brap
Aug 23, 2004

Grimey Drawer
Honestly there's not that much to it. Select to apply a function to the elements of a sequence, Where to filter down to elements that satisfy a predicate, First to get the first element that satisfies the predicate, FirstOrDefault to keep your program from blowing up if one isn't found, Last similarly gets the last item matching a predicate, OrderBy and ThenBy to sort a list, Any to see if any elements in the list satisfy a predicate, All to see if all items in a list match a predicate. Those are what you'll use like 90% of the time.

There is some interesting SQL-like stuff you can do with GroupBy but I've found it pretty confusing in the context of C#.

brap
Aug 23, 2004

Grimey Drawer

RICHUNCLEPENNYBAGS posted:

So we are in agreement.

Tests are only going to be perfect for simple and obvious functions, and it's funny when people act like code without automated tests is a time bomb. It's not that black and white. But the nice thing about tests is you get to be specific and literal about what the expected behavior of your code is. That's really handy when evaluating how well your program fulfills requirements and it's very useful for the poor sap maintaining your code in the future who needs to figure out what the gently caress it does.

brap
Aug 23, 2004

Grimey Drawer
Why is "order by" in sql then

brap
Aug 23, 2004

Grimey Drawer
Ideally a unit test suite should create whatever environment it needs to operate and that includes a test database.

brap
Aug 23, 2004

Grimey Drawer

Dromio posted:

I disagree. Most unit tests should never hit the database. Mock the results of your query and test the logic of your method alone. No need for an actual db. I only hit a database (in-memory) when writing integration tests,

I use Highway.Data to put a decent abstraction layer on my queries. Plays well with EF and NHibernate.

Yes and the stored procedures would benefit from tests too.

brap
Aug 23, 2004

Grimey Drawer
I've got some legacy code with a whole lot of this

code:
private int field1;

public int Field1
{
    get
    {
        return field1;
    }
    set
    {
        field1 = value;
    }
}

// repeat like 20 times in each file
I would rather have this:
code:
public int Field1 { get; set; }
// etc...
Has anyone written a tool to go through a source file and do this?

brap
Aug 23, 2004

Grimey Drawer
Maybe if each property directly followed the backing field. But I actually have a region of fields and a region of properties. It's not good.

brap
Aug 23, 2004

Grimey Drawer

NihilCredo posted:

...but that makes things even easier? Delete the fields, then replace the {get {return (.+?) } set {\1 = value} } pattern* with {get; set;}. Done.

I mean, if you already have ReSharper / CodeRush then yeah, let them do it for you, but if you don't this isn't a huge problem or anything.


* For readability I didn't insert the newlines or escaped the curly braces, that's all you need though.

Good call. I didn't even think of it. Might try to whip that expression up next time I'm at work.

I am tending to avoid resharper based on negative anecdotes and the assumption that if wont be that easy to turn off and on as needed. I am likely to be wrong on at least one of those points.

brap
Aug 23, 2004

Grimey Drawer
Are you serious? EF entities don't just return null if you access a nullable property that contains null? Also, table is not a good name in that context. You are working with individual records, not tables, so it's better to say something like for chair in chairs or for butt in butts.

You're treating this like the SQL database doesn't exist? What do you mean by that?

brap
Aug 23, 2004

Grimey Drawer
Get just the capture group. Groups have automatic number identifiers or can be named. Google knows. Also, write \d{4} not \d\d\d\d.

UberJumper posted:

So apparently after writing C# unit tests for half a week. I have apparently just inherited all responsibilities as lead test developer. The company is small (~20 people), and honestly even after saying "This is a bad idea" and i don't know anything about being lead test developer, they still put me in this position.

The old lead left on apparently bad terms, and there is absolutely no documentation. There is apparently a Jenkins server, that seems to be pulling from a SVN (we swapped to git a year ago). Apparently they just want to start from scratch when it comes to testing, and i am at a complete and utter loss. Does anyone have any tips for doing this kind of degree of testing for C#.

Make sure to check in with the coding horrors thread.

brap
Aug 23, 2004

Grimey Drawer
code:
public Thing Thing {get; set;]
This makes me hate C# conventions so much.

brap
Aug 23, 2004

Grimey Drawer
God drat vb is messed up.

brap
Aug 23, 2004

Grimey Drawer

GrumpyDoctor posted:

& is a string concatenation operator in VB.NET. Did you mean to use AndAlso?

Hahahahaha how do people use this loving language

brap
Aug 23, 2004

Grimey Drawer
Find References to your interface's type if you want to be able to jump to your implementation. Also, check your spelling.

brap
Aug 23, 2004

Grimey Drawer
Oh, shoot. Sorry about the smug.

brap
Aug 23, 2004

Grimey Drawer
So I've got a WCF two way TCP service running in a WPF app, and clients to that service running in a Winforms tray icon app. Right now I have the client app set up to create a new service client and try to reconnect when the fault event occurs. This is supposed to make it so it automatically reconnects if there's a temporary issue communicating with the server. In practice though it causes my server app to freeze if I launch the client before launching the server. What should I be doing differently?

brap
Aug 23, 2004

Grimey Drawer
Are you sure about the scopes? I'm pretty sure I've seen people just open up a block in some C# code so they could redeclare a variable or something. It's kind of nasty when it happens.

brap
Aug 23, 2004

Grimey Drawer
Are there any trip reports out there of people's experience working on ASP.NET projects with Visual Studio Code?

brap
Aug 23, 2004

Grimey Drawer
I use a Mac at home and PCs at work. I think I'm still inclined to spin up my Windows virtual machine with Visual Studio for .NET work.

brap
Aug 23, 2004

Grimey Drawer
I'm working on an MVC 6 Web API project and I'd like to profile it to find out where my performance bottlenecks are. However, when I go to the Debug menu -> Start Diagnostic Tools without Debugging and go through all the steps there, I hit a wall. When it asks me which project I want to profile, the listing says "No launchable projects are available for profiling."

What should I do? Would something like MiniProfiler work if I dropped it in?

brap
Aug 23, 2004

Grimey Drawer
Yay Microsoft and version segmentation. You still have Source Control -> Annotate for what it's worth.

brap
Aug 23, 2004

Grimey Drawer
This basically captures my point of view on DI. It's a good thing and a very simple thing.
http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html

I feel pretty similarly about "inversion of control." Frankly it feels to me like OO programmers discovered modularity and just had to come up with a special term for it.
I think inversion of control is a categorically poor term because it only has meaning in the context of "the way we used to do things."

edit: It's also possible I have no idea what the gently caress I'm talking about.

brap fucked around with this message at 21:24 on Aug 26, 2015

brap
Aug 23, 2004

Grimey Drawer
What property names? You haven't mentioned any object that has properties on it. Is your dictionary supposed to get converted to or interpreted by an object that has some properties in it?

brap
Aug 23, 2004

Grimey Drawer
Ok, I found your post from last week. I think people are just so thrown by your database schema that they can't believe there's a problem here.

I suggest you come up with a function for each model that consumes the dictionary, applies a set of keys to the dictionary and knows the conversion to apply on each value. Take your common stuff like address fields and just come up with functions that turn strings into addresses and addresses into strings for when it's time to convert back. Then call those functions as needed for each property.

I don't think making every property on every model implement a certain interface will meaningfully reduce the amount of boilerplate involved in this. StringKeyValuePairable, NumberKeyValuePairable... then providing parameters in the constructor so they all know what database keys they use, it's still a lot of code to churn out.

brap
Aug 23, 2004

Grimey Drawer
Anybody in here have experience with ASP.NET 5 beta apps on Azure? I'm getting chronic, nasty performance issues: 5 to 12 second response times when all I'm doing is reading a string from a Redis cache and shooting it on toward the client. I also get an occasional issue where my API puts out an empty web page instead of JSON. I'm not sure what to try, except maybe to downgrade to the current version of Web API.

brap
Aug 23, 2004

Grimey Drawer
Honestly not sure. I'm about to get with my friend who's been hosting it using his free azure credit and poke at whatever tools Microsoft provides for profiling a running app. It actually started being responsive at midnight, kept being responsive until a few minutes ago, and is now back at 6 second or so response times.

brap
Aug 23, 2004

Grimey Drawer
Yep, even suffering through "why does this have to be optional" type issues at compile time is much better than nullreferenceexceptions at runtime. And I want it to be an opt-out thing for new projects. You get nullability warnings by default.

It's funny you call async a virus. I guess it does necessarily propagate through your call graph quite a bit--but how else could it work? The alternative is to block a thread at some point in the process. I find that much of the time it's easy to add the async keyword and wrap Task<> around my return type anyway--certainly easier than refactoring my function to consume a callback would be.

brap
Aug 23, 2004

Grimey Drawer
Yeah it's an insanely stupid system. I think the ASP.NET 5 stuff doesn't do this. I also love returning a 503 by throwing a loving exception.

Exceptions are maybe the most misused concept in high-level languages.

brap
Aug 23, 2004

Grimey Drawer
These kinds of things are pretty much inevitable if you want c# code to basically compile into SQL at runtime and execute in your database. It's amazing they've made it as close as it is to the "real thing."

brap
Aug 23, 2004

Grimey Drawer
Well, in practice you probably import Windows.System.UserProfile and then say UserProfilePersonalizationSettings.Current.

brap
Aug 23, 2004

Grimey Drawer
I am really put off by the service locator/view model locator/big ball of singletons pattern. Am I crazy?

Adbot
ADBOT LOVES YOU

brap
Aug 23, 2004

Grimey Drawer

Ciaphas posted:

Yet another reason I wish my work machine wasn't an internet-free security-lockdown hellhole. NuGet packages and other frameworks are a non-starter for me, which probably isn't helping matters as far as learning (at least at work) :sigh:

(ed) I do appreciate the advice that tight one-way coupling of the view to its viewmodel is okay, though. I was beginning to lean in that direction anyway--not having any code-behind even for very view-specific stuff struck me as weird from the word go--but it's nice to have it affirmed.

What industry are you working in, if I may ask?

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