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
NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

At some point in the next few months, we might have to convert a large solution from VB.Net to C#. Is there a general consensus on what is the most reliable translation tool available on the market?

Adbot
ADBOT LOVES YOU

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

chippy posted:

Can I use a List of Strings as a the key for a dictionary?

Or, can anyone think of a neat solution to this? I've got a collection of Foos, each of which has a collection of Strings. I need to find each unique list of Strings, along with the Foos that share it.

p.s. VB, not C#, if it makes any difference.
p.p.s. I am aware that this is a somewhat remedial level question, but I am ill and sleep deprived and it is the end of the day.

From the way you describe the problem, it sounds like you want to start with the Foos as the keys, and the lists of strings as the values, and then turn that "inside-out" into the dictionary you actually want.

GroupBy would fit exactly what you want to do, but as Sedro says it would also require you to define an EqualityComparer (using SequenceEqual). If you would have no further use for the comparer I'd just go with the lo-tech approach of a For Each loop: https://dotnetfiddle.net/fBRDaW

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Speaking of using{}, if a using (foo) {} block lasts until the end of the method, is it in any way different from just declaring foo as a local variable?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Gul Banana posted:

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

Do you have any source that it will not support vb.net, as opposed to just not supporting it now while it's still in beta?

Our company's projects are all in VB.Net, and we're just about to start bringing some of those from the desktop to the web, so it was quite a bummer when I grabbed the MVC 6 starter project, converted to VB everything I could find in the project folder, and it still doggedly showed a reference to MS.Csharp.dll and refused to compile.

It would suck pretty hard to have to choose between learning an already-obsolete framework, and the drudgery of converting some really fat DLLs after persuading the older programmers to switch syntax. (Plus, I like VB.Net better than C# myself.)

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Gul Banana posted:

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

The fact that the guy who answered is the Principal Program Manager Lead on the ASP.NET team and has the handle "coolcsh" is pretty telling of his personal bias :arghfist:

In any case, we're looking at those sexy, sexy DevExpress controls and those may tie us to MVC 5 for at least the short-medium term anyway, since they haven't said a word about vNext support.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

I'm trialing CodeRush and it's insanely faster than ReSharper, which slowed VS2013 down to a crawl. CodeRush has almost no performance impact, is less intrusive (coloured sidebar lines instead of squiggles EVERYWHERE), while also having pretty much all of the features I wanted from RS.

Does that match anybody else's experience? When I was googling them almost everybody seemed to favour ReSharper.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Ochowie posted:

Also, some of the loop to linq conversion suggestions don't make a whole lot of sense and often produce code that is less clear (again in my opinion).

I agree here. Lots of for-each loops can be turned into linq queries, but IMO it's the simpler ones that really benefit from it - those that do the exact same thing as one or two LINQ keywords. More complex enumerations are often easier to grok in loop form, and in particular some of the conversions that ReSharper suggested were eye-gougingly ugly.

Also, the process of debugging a misbehaving loop is obvious, that of debugging a linq query not as much.

NihilCredo fucked around with this message at 21:12 on Feb 11, 2015

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

fleshweasel posted:

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?

Yes, the find / replace tool. This is a great place to use a regular expression.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

fleshweasel posted:

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.

...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.

NihilCredo fucked around with this message at 07:41 on Feb 27, 2015

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

EssOEss posted:

What are the negative things you have heard about ReSharper?

For me, it simply slowed down VS2013 far beyond what I was willing to tolerate. I was considering keeping it just for the occasional refactoring while turning off Code Analysis, but then I tried CodeRush and it provided almost the same functionality at a fraction of the speed penalty.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

If you must maintain XP compatibility and must therefore target .NET 4.0, is it a total no-brainer to grab the BCL Portability Pack to get access to async/await or are there any drawbacks to consider?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Ithaqua posted:

This is basic access modifiers.

  • Public is accessible anywhere
  • Private is accessible only within the class it's defined in
  • Protected is accessible from the class it's defined in and any subclasses
  • Internal is equivalent to public, but only within the assembly it's defined in

Nitpick: Internal in VB.Net is called Friend :glomp:

edmund745 posted:

I have tried looking for this answer online and can't find anything useful, since I suppose the question contains too many keywords.

Using vb.net (VS Express 2012)
1. I have a class/an object.
2. that class/object has a list in it. One of these ---> https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx
3. how do I use the list methods without declaring the list public in the class?

I cannot recall how to do this.... Declaring the list as public works, but it seems odd to do that when you declare all the other properties private.... Seems like there would be a way.

I can find pages that talk about using lists from within the object that contains them,
and pages that talk about objects/properties/methods,
and pages that talk about lists of objects,
and pages that talk about lists of lists,
but I can't find any pages that talk about using a list inside an object, from outside that object.

What, exactly, are the "list methods" you want to access from outside the object?

Reading you literally, if you want to access, say, myObject.myList.Add(item) or myObject.myList.Clear(), then yeah, making the list public is what you want to do. (crashdome is correct that you can use a readonly property to let people use the List methods, without being able to outright replace the List with a new one. But in the particular case of a List, this wouldn't do much since people could just call .Clear() to empty the list and .AddRange() to replace it with anything they want. All a "readonly" modifier really does in this case is prevent people from setting the list to Nothing and causing trouble.)

If you want to let people use only some methods of the list - a common case would be the ability to add stuff but not remove it - then you set up a few public methods or properties that expose only the stuff you want from the private list.

If you want to access the individual objects inside the list, but not the list itself, same thing - add properties that fetch the items, without revealing anything about the list (or even that there is a list).

Example:

code:
public class myClass

private myList as list(of item) = new list(of item)

'this method will let outsiders add stuff to the list, but they won't be able to do anything else
public sub AddItem(newItem as item)
if mylist is nothing then mylist = new list(of item)
mylist.add(newItem)
end sub

'this will return a single item from the list if available, and is also a pretty stupidly written property
public readonly property GetItem(index as integer) as item
get
if mylist is nothing orelse mylist.count <= index then return nothing else return mylist(index)
end get
end property

'better version: this will return an "IEnumerable", the tl;dr version of which is that it is a collection that you can filter, search, iterate ("for each"), etc. through, but not actually modify (add/remove stuff)
'if you just returned a List the "readonly" wouldn't really protect you - it would prevent people from replacing the list outright but they could still e.g. call .Clear() and .Remove() on it
public readonly property myItems() as ienumerable(of item)
get
return mylist  'since a list is a kind of IEnumerable you can just return it - external objects accessing the property will not know that it could do more, as the List-specific stuff like Add() or Clear() will remain unavailable
end get
end property

end class

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt


Either that or use a Using afile As New FileIO.TextFieldParser(filename) block.

Setting objects to Nothing is not actually disposing of them. :iiaca: You're not demolishing your car, you're just throwing away your car keys and hope somebody notices the abandoned car and gets around to demolishing it. In this particular case, you're throwing away the keys of a running car.

NihilCredo fucked around with this message at 22:17 on Apr 1, 2015

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

You can also combine multiple Using variables in a single block, and terminate your loop by checking for .EndOfStream instead of waiting for a null :eng101:

Also, I wouldn't bother checking for file existence. You want to handle I/O exceptions anyway, because file permissions / drive access / network access could drop at any time during the operation, so might as well write the code only once.

Visual Basic .NET code:
Try

	Using reader As New System.IO.StreamReader(strFilename),  
	      writer As New System.IO.StreamWriter("new file name")

		Do Until reader.EndOfStream
			writer.WriteLine(reader.ReadLine().Replace("thing1", "thing2"))
	    Loop
	
	End Using

Catch exception as System.IO.FileNotFoundException
	MsgBox("File not found!")
Catch exception	as System.UnauthorizedAccessException
	MsgBox("Access denied!")
'etc.
Catch exception as Exception
	MsgBox("Error: " & exception.GetType().ToString)
End Try
Unrelated:

I'm trying to learn the ropes of F#, and I don't quite get why I must always put an identifier in discriminated unions.

Basically, it seems to me that this ought to be legal code:

code:
module myModule = 

    type myType = //...

    type myUnion =
        | double
        | string
	| myType
        
    let myFunction (someArgument : myUnion) = 
        match someArgument with
            | double -> printfn "It's a number!"
            | string -> printfn "It's a string!"        
            | myType -> printfn "It's my type!"        
        
    [<EntryPoint>]
    let myMain args = 
        myFunction 100.0
        myFunction "qwerty"
	myFunction (new myType())
        0
but instead I'm forced to assign three unique identifiers to myUnion's sub-types, at which point I can't just call myFunction on a raw double or myType, and instead have to wrap them up with their respective identifiers.

Can anybody help me understand if there's a reason the above code is not allowed?

NihilCredo fucked around with this message at 00:47 on Apr 11, 2015

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Yesterday I was trying to speed up a fairly intensive procedure when I noticed that, no matter how much I cut down on the work it had to do, it wouldn't go under 5-6 seconds execution time.

Then I realised that most of that time was actually being spent on the initial setup: looping through the DataTable containing the query results and setting up the business logic objects based on its contents. But this DataTable was barely a thousand rows, and the "building" wasn't doing any real work either ("if [Type] = "A" then add ([Name], [Quantity]) to SomeList else add to SomeOtherList", stuff like that) - I couldn't fathom why it would be so slow.

Almost on a whim, I tried changing the For Each loop to a For loop. I fully expected nothing to happen... instead lo and behold, the loop became almost instant :psyduck: (Still noticeable, but well under a second.)

Does that sort of behaviour ring a bell to anyone? Everything I can google says that the difference in iteration speed should have been insignificant. Casting to IEnumerable couldn't possibly have triggered some schema validation or anything of the sort, I hope?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Ithaqua posted:

This is all from memory:

Probably an implicit cast is happening. I assume you're doing foreach (DataRow row in whatever.Rows), right? Data tables are pre-generics... Rows is a RowCollection or something similar, and getting stuff out of it requires casting back from object.

You can validate if I'm insane or not by changing the "DataRow" in the foreach to "var".

That makes a worrying amount of sense. I'll try that tomorrow, thanks!

It seems odd to me that casting would be that expensive, especially when I'm checking for the "original" type. You'd think that looking at the type token and seeing that yep, it matches, would be pretty fast; if nothing else, the fastest of all possible casts.

If that's indeed the guilty party, then at least I can keep using the prettier For Each as long as I drop the As DataRow part - and since accessing cells by column name is already horribly unsafe anyway that's quite fine. But, I'll also have to quit using LINQ on any DataTable of non-negligible size :smith:.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Onion Knight posted:

Is the Windows 10 registry different than previous versions of windows?

It seems like 10 will save registry values as typed, but 7/8 saves objects that need to be parsed. Specifically I'm doing this:
code:
bool hotkeyCtrl = Convert.ToBoolean(key.GetValue("hotkeyCTRL", false));
Which works on 7/8 but fails on 10. However:
code:
bool hotkeyCtrl = (bool) key.GetValue("hotkeyCTRL", false);
Works on 10 but fails on 7/8.

Is there a better way to go about this? Is there a right way to add a shim for Win10? Just check Environment.OSVersion?

This ought to do the trick:

code:
Convert.ToBoolean( (object) key.GetValue("hotkeyCTRL", false))
Won't do anything on 7/8, on 10 it will box the boolean and then immediately unbox it back.

EDIT: Although I'm not sure why you're getting that exception in the first place, since Convert.ToBoolean should accept boolean inputs quite fine. This works in dotnetfiddle, for example:

code:
using System;

var rand = new Random();

for (int i = 1; i <= 100; i++)
{

var SchrödingersRegistry = rand.Next(2) >= 1 ? true : (object) "FALSE";

Console.WriteLine(Convert.ToBoolean(SchrödingersRegistry));
}

NihilCredo fucked around with this message at 11:01 on May 3, 2015

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Onion Knight posted:

Once I get Windows 10 on my laptop I'll test it again with NihilCredo's solution, just in case.
As I edited in later, there shouldn't be any need to cast to Object, because Convert.ToBoolean() has an overload that takes a boolean argument; the first snippet you posted should work just fine. The cast wouldn't do any harm, but it would also be pointless and confusing.

Cryolite posted:

How safe is it to install VS2015 RC alongside VS2013? I vaguely remember reading something that said you should only install VS2015 in a VM or something that can be reformatted. Was this only for the CTPs or something like that? When it's actually released, will I be able to completely uninstall the RC and install the actual release, without messing up my system?

Have been running the CTP alongside VS13 for a few months now (for messing around with F#4 and with vNext, while I did production work on VS13), never had any problems.

If all my plugins work fine I'll probably switch over to VS15RC for production work too; side-by-side installations are a little expensive on a SSD.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Dietrich posted:

ungh web development in vs 2015 is like learning a whole new tool set with Gulp and Bower.

Lots of development in 2015 seems to be about constantly learning new, totally essential open-source plugins and packages that you're supposed to discover through sheer memetic osmosis more than by any structured process.

"What, you don't even Squazzle your assemblies or check them in Hoobilai before you Dripr them to a Kanoozer stack? You just compile and run? Jesus do you write COBOL programs for AS/400 or something?"

(Say what you will about boring-rear end '90s enterprise software, but if somebody says that they're having good/bad results with MegaCorp Distributed Database Mapping Manager 5.0, I don't have to hit up Google to figure out if it's a tool that I care about.)

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

chippy posted:

Ahhh, thanks, I'll give this a go. I actually already tried pretty much exactly this, but I was using KeyDown, so taht explains why that wasn't working.

For another option, I wouldn't bother dealing with input at all, instead I would handle the TextChanged event directly and get rid of any carriage returns.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

So if you want to create a WebSharper website, what are your options for good-looking UI controls beside KendoUI?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

AuxPriest posted:

There's http://www.syncfusion.com but they have a similar price tag as Kendo Ui.

Thanks, but what makes you say that SyncFusion works with WebSharper? I can't find any mention of either on the other's page

The price tag for the UI library I don't mind - my boss has already committed to buying something nice in that area. But a WebSharper wrapper (premium extension) that costs as much as a DevCraft license would be a much harder sell, when there is no such additional cost for MVC; I could probably make the case for purchasing a WebSharper commercial license instead of a UI library, but not on top of one.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Bognar posted:

However, it looks like you could just use List.exists or List.forall with a mapping function instead of piping to Seq.exists. The LINQ corollaries are .Any() and .All(), respectively.

Any(), All(), or exists() are the correct functions to use here as they will short-circuit as soon as they find a (non-)matching element.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Mr Shiny Pants posted:

I am writing a F# program and need a timer. What is a good timer for F#?

In C# I have used the RX observable.FromTimespan with good results, but RX is pretty ugly to use in F# because of the overloaded nature of most methods.

Is System.Timer the best?

I saw one using a MailboxProcessor with do! async sleep in it which I thought was pretty funky.

Have you read this implementation with Timer and (F#) Observable? It doesn't look particularly ugly to me.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

LeftistMuslimObama posted:

The whole concept of having multiple parts of each type is what makes it dumb. I get having a separate style part and worksheet part. Cool, separation of purposes. Having multiple worksheet parts that contain your document's worksheets is dumb. Just give a "get worksheets" method that returns a collection of all the worksheets, and require devs add new worksheets via that collection. Don't arbitrarily add parts whenever you want to add sheets. I should just be able to do something like
C# code:
Foreach(sheet s in workbook.sheets) 
And get every sheet. It's silly.

A while ago I had to manipulate some data in an Excel file so I just used Microsoft.Interop.Excel.dll and I remember it being very straightforward; you do need to have Excel installed though.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

GrumpyDoctor posted:

I accidentally just wrote an event handler for A that caused event B to fire, which in turn had a handler that caused A to fire, but the resulting infinite loop didn't blow my stack. Is that as impressive of a runtime achievement is it seems?

Not really, I think.

Events are async, so each handler will happily terminate and GTFO of the stack after firing off the event that continues the loop - kinda like TCO, in a way. In a normal infinite loop you blow the stack because there's an endless chain of calling functions that never got to terminate, but that doesn't happen here.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

GrumpyDoctor posted:

I had never heard this before. Do you know somewhere I can read about it?

Ok, sorry there, midnight brain fart, forget what I said.

I'm so used to putting events, particularly UI events, on async execution (event handlers just wrap a threadpool call) that I forgot it's not the default behaviour.

Event handler methods, by themselves, are blocking and synchronous.

There still could be several reasons why your loop didn't explode. Maybe one of the events only actually fires after the method is exited, maybe you're using WaitHandles in a way that prevents the problem... I'd like to see the code, to be honest.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

The King of Swag posted:

Maybe I'm just not understanding exactly at what level of the compilation process the safe navigation operator (?.) is working at, but despite developing using the .NET 4.0 runtime, VS2015 is recommending I use it, and sure enough, it actually works. So what's going on here? Is the compiler just compiling it in a way that it still functions with the older runtimes?

Language version and .NET Framework versions are two different things, yes. The framework mostly just changes the libraries you work with.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

chippy posted:

WinForms: I just want a property of the form (very simple dialogue for entering a single number) to always reflect the value of a NumericUpDown in the form.

Based on those specs, is there any reason you can't just write

code:
public readonly property HoursWorked as integer
if hoursNumericUpDown is nothing then return 0 else return hoursNumericUpDown.Value
end property
instead of using WinForms's lovely stringly typed databinding?

(If you do need to use databinding, VB14's NameOf function should at least help with type-safety.)

NihilCredo fucked around with this message at 19:41 on Aug 6, 2015

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Does anyone know if the ASP.NET MVC Boilerplate template that's on Visual Studio Gallery is any good? Are there any recommended alternatives?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

quote:

Add a notion of safe nullable reference types T? to the language, in addition to the current ones T which are from now on non-nullable.

quote:

From a semantic viewpoint, T and T? are mostly equivalent: they are the same type in that they have the same domain of values. Specifically, because the system is far from watertight, non-nullable reference types can contain null. The only way in which they differ is in the warnings caused by their use.

I don't quite get how that would different from the existing Nullable<T> a.k.a. T? structure, which can already be used to wrap any reference type (even though that's not its intended purpose).

The only new thing in the proposal seems to be the compiler warnings for lack of null-checks / null-propagation.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

LOOK I AM A TURTLE posted:

Not sure what you mean by saying that T? can wrap any reference type. T? today is always translated to Nullable<T>, which can't be used on reference types because it has a where T : struct constraint: http://referencesource.microsoft.com/#mscorlib/system/nullable.cs,27.

You're right. I was confused by a recent discussion in another thread.

quote:

Personally I like the proposal. It's a good compromise that allows backwards compatibility but should give much better practical safeguards against boneheaded NullReferenceExceptions. Of course we'd all rather have truly non-nullable reference types in C# if we could, but I don't think there's any realistic way to retrofit that at this point.

Compiler option maybe? I mean, if VB.Net can have Option Strict which basically switches it from a strongly-typed to a weakly-typed language, I don't see why you can't introduce some sort of Option Nullable.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Gul Banana posted:

maybe if an *entire* language was async, coroutine based or green-threaded, you could avoid the infecting type..?

Erlang?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

So, let's say I have a SQL table of a few thousand rows that I want to store in memory, as it will be frequently and randomly accessed. The table has only 6-7 relevant columns, all short strings or numbers.

In the business logic, each row translates to an instance of a class which isn't quite a POCO, since it features a Parent property that returns (lazily) the instance identified by the ParentID column, plus a few static methods to find common ancestors and the like. (The fact that the class is self-referential is important, since otherwise I could have made it a struct.)

Am I more likely to be better off :

A) loading the table into memory as a DataTable and, when necessary, grabbing the row by the provided Id and instantiating the class from the row (and then throwing it away)

or

B) immediately loading the table into memory as a big Dictionary of string -> class

?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Pause for a second. I thought DST always took effect at 2 AM <-> 3 AM?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

fleshweasel posted:

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."

That's why I love FSharp.Data.SqlClient so much. Give me the type safety and otherwise just let me write straight SQL: it's easier (and far, far more useful) to learn to write good SQL than to learn the quirks of an ORM's DSL.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Manslaughter posted:

Is there a way in visual studio to check a project for all uses of any enums? I'm having serialization problems with them, but its not just one specific enum, and I have a few hundred of them to sort out (tool generated).

Do a find/replace over the declaration page for "public enum " -> "public enum BUTTS_", then go through the error list?

(Also known as the "wow girl these hammer-shaped glasses are really makin' you look thin and sharp" method.)

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

GrumpyDoctor posted:

Holy god I just learned about "Paste Special->Paste XML As Classes" this is amazing :psyduck:

It's cool as poo poo, but be sure to FULLY review the output or you may have some nasty surprises down the line.

NihilCredo posted:

Random cool thing about XML: Visual Studio has a feature called "Paste XML as classes" which does exactly what it says on the label and it looks loving magical.

Until one week later the deserialisation mysteriously starts failing, and you discover that the sample XML you pasted in had been generated in the first few days of the month, so VS made the "date" fields into UInt16s instead of UInt32s.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Your problem is that GetByManufacturer returns a collection of Automobiles. It makes no promises about those being Cars or Trucks - for all you know the implementation might completely ignore the input and just output a fixed mix of both - so they cannot be implicitly converted as such.

To fix that, make GetByManufacturer into a generic function:

code:
        public static  IEnumerable<AutomobileType where AutomobileType : Automobile> GetByManufacturer(IEnumerable<AutomobileType> items,	 string manufacturer)
        {
            return items.Where(o => o.Manufacturer == manufacturer);
        }
This way GetByManufacturer promises that it will return the same subclass of Automobile that it received in the "items" argument.

Adbot
ADBOT LOVES YOU

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

GrumpyDoctor posted:

Also, is that generic method syntax right? I thought it should be
Yeah, I was going by memory and ended up with a hybrid of C# and VB syntax :) Thanks for the fix.

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