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
xgalaxy
Jan 27, 2004
i write code

EssOEss posted:

A common idiom I use that takes advantage of that is the named constructor, to make it clear and obvious that creating an instance is nontrivial.

You could also use the builder pattern here too:

code:
    public class Complex
    {
        private int _foo;
        
        private Complex()
        {
        }
        public class Builder
        {
            private Complex _complex = new Complex();
            
            public Complex Build(int foo)
            {
                if (_complex == null)
                   throw new InvalidOperationException();

                _complex._foo = foo;
                
                var retVal = _complex;
                _complex = null;
                
                return retVal;
            }
        }
    }

xgalaxy fucked around with this message at 16:10 on Nov 4, 2015

Adbot
ADBOT LOVES YOU

Inverness
Feb 4, 2009

Fully configurable personal assistant.

NihilCredo posted:

The downside in this case is that you cannot make the constructor private (because the method/s wouldn't have access to it), which is something you want to do if the class isn't supposed to be created by anything other than your method/s.

Not a big deal if it's just a dumb wrapper, though.

edit: for some OOP masturbation, if it were a big deal, what would be the cleanest solution? I tried to whip up something with 'protected' but it wouldn't stop people from inheriting and instantiating the class. There's no access modifier for "accessible only to this one other class", unless you can make the thing its own assembly and go with "internal". I think the only "proper" solution is to make and return an interface and keep the implementing class private, but that does force you to code up the object properties twice.
The proper way to do this in C# is to make a public class with an internal constructor. The internal constructor stops inheritance since classes outside of your assembly would have no way to invoke the base constructor.

There is no way in C# to make that constructor "accessible only to this one other class", but it's not necessary. Internal fits the bill and comes with the general assumption that you have control of those classes in the same assembly and what they do, which is a reasonable assumption to make.

NihilCredo
Jun 6, 2011

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

Nitrocat posted:

i find the abilities such as converting loops to linq expressions [..] to be vital

I don't understand why this is usually named as one of R#'s MVP features.

If you find Linq easier to use, why aren't you writing stuff in Linq in the first place, instead of using loops?

Vice-versa, if you find it easier to express yourself with loops, why wouldn't you keep them as loops instead of converting them to a form you don't grok as well?

I can see the feature being handy when refactoring third-party code, but that shouldn't be an everyday sort of activity, should it?

Kekekela
Oct 28, 2004

NihilCredo posted:


Vice-versa, if you find it easier to express yourself with loops, why wouldn't you keep them as loops instead of converting them to a form you don't grok as well?

I think a lot of people use it as a learning tool, since they initially learned the pre-linq syntax. But yeah, that should be something you do a few times until you get the hang of it.

raminasi
Jan 25, 2005

a last drink with no ice

Kekekela posted:

I think a lot of people use it as a learning tool, since they initially learned the pre-linq syntax. But yeah, that should be something you do a few times until you get the hang of it.

I know a guy who loves R# for exactly this reason.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



NihilCredo posted:

I don't understand why this is usually named as one of R#'s MVP features.

If you find Linq easier to use, why aren't you writing stuff in Linq in the first place, instead of using loops?

Vice-versa, if you find it easier to express yourself with loops, why wouldn't you keep them as loops instead of converting them to a form you don't grok as well?

I can see the feature being handy when refactoring third-party code, but that shouldn't be an everyday sort of activity, should it?

LINQ is a decent-sized API all on its own and then a lot of people have written extension libraries for it. I feel pretty comfortable using it but I'm occasionally surprised when R# says I can convert a thing I just wrote.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Munkeymon posted:

LINQ is a decent-sized API all on its own and then a lot of people have written extension libraries for it. I feel pretty comfortable using it but I'm occasionally surprised when R# says I can convert a thing I just wrote.

Sometimes it is nice to leave it as you originally wrote it, rather than have it as a Linq. Sometimes it would produce linq queries that were not exactly easy to see exactly what it was doing just by looking at it. It is handy to have though.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Drastic Actions posted:

Sometimes it is nice to leave it as you originally wrote it, rather than have it as a Linq. Sometimes it would produce linq queries that were not exactly easy to see exactly what it was doing just by looking at it. It is handy to have though.

Oh agreed - I always curate its suggestions. It suggests some janky poo poo in cshtml files sometimes for instace

lord of the files
Sep 4, 2012

NihilCredo posted:


Vice-versa, if you find it easier to express yourself with loops, why wouldn't you keep them as loops instead of converting them to a form you don't grok as well?


i don't find my self consistently using either, but I do use it as a learning tool and from that I think that some problems are better solved with linq and others with loops. sometimes i have been surprised when r# notifies me that a loop can be a linq expression. for my personal projects I tend to leave the loops due to how I tend to skim large chunks of code, and having the ability to just glance at a loop and know what it does is handy.

amotea
Mar 23, 2008
Grimey Drawer
Resharper boosts productivity tremendously TBH, especially in huge codebases or when refactoring old/other people's code. This is what I use it for off the top of my head (in no particular order):
- Rename (w/ overloads)
- Change signature (useful to change method in entire hierarchy)
- Move blocks around
- Go to next error in file or solution (requires global analysis on)
- Find issues in projects (code smells)
- Code formatting (way more advanced than what VS offers)
- Remove unused references
- Apply a fix in entire file/project/solution
- Generate constructor
- Generate delegating members
- Generate missing member implementations
- Refactor stuff to use C#6 features
- Loop refactoring from/to LINQ
- LINQ simplification
- Suggest passing of CancellationToken when possible
- Go up/down the inheritance hierarchy on a symbol
- More advanced 'find usages'
- Quickly fix naming in pasted 3rd party code
- Removal of redundant code or symbols
- Hints when code/symbol isn't used
- Simplification of (logical) statements
- Pull members up/extract interface
- Push members down
- Extract method
- Inline method/variable
- Change signature of caller/callee to match what callee/caller wants
- Generate method/class from the way I just tried to use it
- Check for null in constructor
- Generate and initialize fields from constructor arguments
- Static checking annotations: CanBeNull, NotNull, ItemNotNull, ItemCanBeNull, Pure
- Code snippets to generate e.g. attached properties, INotifyPropertyChanged etc.
- Generate equality members

I'm probably forgetting some stuff, but this is what I use daily not just every now and then. So yes, I'd say it's still relevant. VS2015's quick fixes don't even come close.

xgalaxy
Jan 27, 2004
i write code
I just discovered GitLink (https://github.com/GitTools/GitLink).
Holy poo poo this thing is awesome.

It rewrites the pdb to point to the versioned file in Git. No need to run a separate symbol server.

EssOEss
Oct 23, 2006
128-bit approved
What exactly does it do? What is the use case and workflow involved? The readme goes into great depth on command line options but the main point appears to be expressed via a tiny GIF that I cannot understand.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
That's pretty neat, I had no idea you could even do something like that.


EssOEss posted:

What exactly does it do? What is the use case and workflow involved? The readme goes into great depth on command line options but the main point appears to be expressed via a tiny GIF that I cannot understand.

From what I can tell, it lets you debug into external libraries (e.g. from NuGet) if their code is available on a publicly accessible git repo.

xgalaxy
Jan 27, 2004
i write code

Bognar posted:

That's pretty neat, I had no idea you could even do something like that.


From what I can tell, it lets you debug into external libraries (e.g. from NuGet) if their code is available on a publicly accessible git repo.

^^ This. But it can also work with a private repo, within a company for example. It looks like they are adding support for a bunch of different public hosting sites now but the two they have currently support for are GitHub and BitBucket. Honestly feel this is something that should be officially supported by Microsoft. The sources.jar that the JVM world has is very beneficial and is something I've always been kind of jealous that .NET never had a good alternative. This GitLink thing just may be the ticket if it starts seeing wider adoption.

xgalaxy fucked around with this message at 16:29 on Nov 6, 2015

kingcrimbud
Mar 1, 2007
Oh, Great. Now what?
Code First Existing Database Entity Framework Question

I'm using Code First with its fluent type configurations currently. I'd like to transform the following table into the following model.

Existing Database:
code:
Customer Table			
ID	FirstName	LastName	Phone (not null)	        WorkPhone (null)	    CellPhone (null)
int	varchar(30)	varchar(30)	varchar(20)	                varchar(20)	            varchar(20)
Proposed model:

code:
    public class Customer
    {
        public int ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public IEnumerable<Phone> Phones { get; set; }
    }
code:
    public class Phone
    {
        public string AreCode { get; set; }
        public string Number { get; set; }
        public PhoneType? Type { get; set; }
    }
code:
    public enum PhoneType
    {
        Home,
        Work,
        Cell
    }
In this way a customer will have either 1, 2, or 3 phones in its Phones collection, each with a different type.

Is this even possible or am I going to need to mess around with extending the Customer and Phone classes to create "proxy" classes and then "newing" properties in the derived types? There's also another issue that phone number values are stuffed in other columns of other tables as well.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

kingcrimbud posted:

Code First Existing Database Entity Framework Question

I'm using Code First with its fluent type configurations currently. I'd like to transform the following table into the following model.

...

In this way a customer will have either 1, 2, or 3 phones in its Phones collection, each with a different type.

Is this even possible or am I going to need to mess around with extending the Customer and Phone classes to create "proxy" classes and then "newing" properties in the derived types? There's also another issue that phone number values are stuffed in other columns of other tables as well.
Why not simply have Phone, WorkPhone, and CellPhone properties in the Customer class as it is shown in the existing database?
code:
  public class Customer
    {
        public int ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Phone { get; set; }
        public string WorkPhone { get; set; }
        public string CellPhone { get; set; }
    }

Sedro
Dec 31, 2008
You could throw in a computed property for Phones and have your ORM ignore it

kingcrimbud
Mar 1, 2007
Oh, Great. Now what?

Inverness posted:

Why not simply have Phone, WorkPhone, and CellPhone properties in the Customer class as it is shown in the existing database?

The existing database is but one system of several that I need to bring together into a common model.

In your example, what if a customer had several cell phones? Why stop at those 3 types of phones? We now have [num of phone type] lists as properties of a customer. I'd prefer one list as a property which is a bit more extensible imo.

Sedro posted:

You could throw in a computed property for Phones and have your ORM ignore it

That's what I was working towards today but it was getting messy with logic in properties, unnecessary inheritance, etc. I wanted to see if I was just completely missing something obvious.

crashdome
Jun 28, 2011
Personally, I would start with the database. Have the DBA (or yourself if that's the case) run a procedure to extract the phone #s to another table. Then code to that.

Or maybe I missed something with your question? Is the table used in another project that's preventing you from altering it?

kingcrimbud
Mar 1, 2007
Oh, Great. Now what?

crashdome posted:

Personally, I would start with the database. Have the DBA (or yourself if that's the case) run a procedure to extract the phone #s to another table. Then code to that.

Or maybe I missed something with your question? Is the table used in another project that's preventing you from altering it?

I would love to but the table is currently backing an old and not going away anytime soon large support application with a lot of traffic.

The question remains; is this a roll-your-own scenario?

EssOEss
Oct 23, 2006
128-bit approved
I would say so. ORMs are no good at doing fanciful "I wish I could fix my tables" style transformations. Use them ONLY for mapping between equivalent data sets, not for converting data into a different format. Or you will be sorry.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

kingcrimbud posted:

The existing database is but one system of several that I need to bring together into a common model.

In your example, what if a customer had several cell phones? Why stop at those 3 types of phones? We now have [num of phone type] lists as properties of a customer. I'd prefer one list as a property which is a bit more extensible imo.
I'm not experienced enough with ORMs to know what to suggest as far as getting the ORM itself to do it.

My other choice would be to have a conversion between model classes at the layer where you invoke the ORM.

Basically, define the Customer class I posted before as CustomerOldStyle or some relevant name. Write some code to convert that to the new-style Customer class that you want. Likewise when placing new customer objects in the database they would need to be converted to the old style that the ORM understands.

chippy
Aug 16, 2006

OK I DON'T GET IT
I've never used sprocs with EF so this is speculation, but could you perhaps craft one that essentially returned the data as if it were stored using the desired schema, and map the results of that to your object?

crashdome
Jun 28, 2011

kingcrimbud posted:

I would love to but the table is currently backing an old and not going away anytime soon large support application with a lot of traffic.

The question remains; is this a roll-your-own scenario?

If your original table is tied to another application and you want more than 3 phone numbers, I don't understand how you are going to do this without yet another table and some weird trickery and shoehorn code tbh.

The big problem you are going to run into is when your large support application does an update to a phone number in the original table.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
I think we might finally be rewriting our monotholic webforms+ext.net project. Has anyone used reactjs+flux with a WebAPI? If so, where did you get started? I know there is a reactjs.net but from what I was reading, no documentation on using flux, etc.

xgalaxy
Jan 27, 2004
i write code

Uziel posted:

I think we might finally be rewriting our monotholic webforms+ext.net project. Has anyone used reactjs+flux with a WebAPI? If so, where did you get started? I know there is a reactjs.net but from what I was reading, no documentation on using flux, etc.

Don't use flux. Use redux (https://github.com/rackt/redux) instead. But this whole discussion is not really .NET related now.
Also, you could skip the kool-aid "flux architecture" and instead use RxJS.

xgalaxy fucked around with this message at 23:23 on Nov 9, 2015

Uziel
Jun 28, 2004

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

xgalaxy posted:

Don't use flux. Use redux (https://github.com/rackt/redux) instead. But this whole discussion is not really .NET related now.
The project would still be in Visual Studio though so wanted to see if there were any gotchas, or specific resources/learning paths for someone familiar with C# Visual Studio and mostly spaghetti style javascript files sprinkled all over a solution.

epswing
Nov 4, 2003

Soiled Meat

Uziel posted:

I think we might finally be rewriting our monotholic webforms+ext.net project. Has anyone used reactjs+flux with a WebAPI? If so, where did you get started? I know there is a reactjs.net but from what I was reading, no documentation on using flux, etc.

Boy would I hate to be the "which JS framework should we use" decision maker in this day and age. Jesus.

<-- Edit: someone tell me why it says Fun Shoe right here :confused:

epswing fucked around with this message at 23:27 on Nov 9, 2015

xgalaxy
Jan 27, 2004
i write code

epalm posted:

Boy would I hate to be the "which JS framework should we use" decision maker in this day and age. Jesus.

I know. There are so many loving different libraries that do the same poo poo. And they are all wrapped in package manager inception.

Uziel
Jun 28, 2004

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

epalm posted:

Boy would I hate to be the "which JS framework should we use" decision maker in this day and age. Jesus.
Yeah...horrible. Ext.net was awesome for our use case, but it's time to move on to something a bit more modern as IE11 and Chrome are now default on all user desktop images.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



epalm posted:

<-- Edit: someone tell me why it says Fun Shoe right here :confused:

Did you donate to the DB3 memorial fund?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Uziel posted:

The project would still be in Visual Studio though so wanted to see if there were any gotchas, or specific resources/learning paths for someone familiar with C# Visual Studio and mostly spaghetti style javascript files sprinkled all over a solution.

You honestly might want to wait until ASP.NET 5 drops in VS2015. They're adding support for JS task runners, which is basically a necessity when building a React website. We put something together last year that runs the JSX compiler as an MVC Bundler, but overall it was more of a pain in the rear end than I would like.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
We're doing a major rewrite of an internal tool in react with webapi (mvc6). It's good. I'll write a bit more when I'm off my phone.

Uziel
Jun 28, 2004

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

Bognar posted:

You honestly might want to wait until ASP.NET 5 drops in VS2015. They're adding support for JS task runners, which is basically a necessity when building a React website. We put something together last year that runs the JSX compiler as an MVC Bundler, but overall it was more of a pain in the rear end than I would like.
Good to know, thanks!

uncurable mlady posted:

We're doing a major rewrite of an internal tool in react with webapi (mvc6). It's good. I'll write a bit more when I'm off my phone.
Awesome, I'd appreciate that!

EssOEss
Oct 23, 2006
128-bit approved
I would also like to declare my great interest in hearing about your experiences with that!

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
Ok, here's a little bit about our React experience over the past few months. Keep in mind that since this is an internal tool, it's basically just me and another guy working on it, and we don't get a lot of time to work on it because the current version works (but is an unmaintainable horror show).

- We (I) decided to use MVC6 because I wanted to break our hard dependency on IIS, and because I'm a rebel, dammit. This has proven to been only a vague pain in the rear end because each ASP.NET 5 beta release has required a few days of refactoring to un-gently caress things that got hosed. I'm still happy that we're using it though, because there's so many things that just make more sense and it'll put us in a good position to break out of the Windows ecosystem once EF7 gets shored up enough to be production ready. I'd definitely wait until the RC1 release this month before starting any 'real' projects, though.

- One of the biggest benefits of doing stuff in MVC6 is, honestly, being able to have type-safety and poo poo from the front to the back end. With React, you're tossing most of those benefits away in favor of a clear separation of concerns between the front-end and the back-end. We've settled on sort of a MVVMC thing, where our models and controllers are in ASP.NET (EF6 for the models/ORM, MVC6 WebApi for the controllers) and then React handles view models and views in JS and JSX.

- The good news is, if you want to do all of this in VS, you can totally do all of this in VS2015. It supports JS-based task-runners in ASPNET5 projects, so you can set up your JSX->JS converters, your browserify (which lets you write all of your React components and classes in separate files and then combine them later), whatever else you please. You can use Grunt or Gulp to do this, and they're supported in the UI and build process (so you can set pre-build targets, clean targets, etc.) VS2015 also understands JSX syntax, R# 10 will understand JSX, and you can get some intellisense in terms of code completion and whatnot.

- The bad? news is stuff you should be girded for - it's Javascript. You're going to have to figure out some way to handle mapping your models into view models. The way we set it up is probably not the best way - we make an initial call to the controller for the data for a page as a bunch of metadata, and then pack that into a top-level view model. Each child component will get some of these properties via their own properties object, and they're responsible for making the calls to populate themselves with the necessary data they need. We use jQuery for most of these AJAX calls. This, looking back, is a mistake - using Flux or Redux or some other form of data store that's meant to integrate with React would have made life easier. That said, it's not awful, it's just kind of annoying because it leads to poor design practices.

Consider a simple table. I want to be able to change some element in the table and have that change be reflected back in the DB. To get the data for the table, I essentially get a big ol' JSON blob of key-value pairs, and then have a React component (which is the child of several other react components) that spits out the table row with that data and the other necessary markup. However, I have a problem when I change something in the table. Only the deepest child object knows that the data changed (because React's entire data model is that things flow from parents to children). There's a few ways I can handle this, conceptually - the 'right' way is to have some sort of data store that implicitly sets a callback on a view model and whenever a part of that object changes, it fires off and handles the change however I want. That can be sort of a pain to put together, though, so I opted for the easy/bad way of ensuring that the necessary metadata I need to make the request to change something is passed down along with the data that's being displayed to that innermost child and have it manage the update event. This works fine, don't get me wrong - it can just be hard to keep track of. It's not impossible to debug, however - the React extension for Chrome is very very good and allows you to inspect your properties and state easily enough.

If I did it again, I'd use some sort of data store though.

- The ugly... is minimal, really. React has pretty good docs and not a whole lot of cruft. You have classes, classes can have children (which are other classes), and you define all of the 'markup' in a render function that allows you to use JSX (which is basically HTML syntax with a few changes that gets converted to actual JS by a JSX converter; it's a one-liner in your gulp file). We decided to organize things into containers and components - a container is a single file that defines a view, and each page you navigate to is a HTML stub that loads that container file into a div. You could also do a SPA with this, we separated it out into pages for... some reason that I can't recall. If you're super comfortable in VS, well, like I said - you can basically stay in VS for quite literally all of this.

There's a bunch of other crap I haven't really gotten into that's more React-specific, but the short version is that it's probably less bad than a lot of other things out there like Angular 1 and Knockout and whatever and it works pretty great with VS2015 + ASP.NET 5. If you have any other questions just lemme know or PM me.

authwiggidywack
Oct 29, 2013


I want to make the simplest version of solitaire I can - my main concern right now is the visual aspect of it (least amount of experience). I don't believe the default console has the room for displaying / rendering the board.

Should I just go for something popular like MonoGame? Any other alternatives or ideas?

Uziel
Jun 28, 2004

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

uncurable mlady posted:

Ok, here's a little bit about our React experience over the past few months. Keep in mind that since this is an internal tool, it's basically just me and another guy working on it, and we don't get a lot of time to work on it because the current version works (but is an unmaintainable horror show).
Wait, are you me from the future? This is the exact same scenario I'm in: internal tool, two developers, me pushing for cutting edge technology, not a lot of time to work on it due to current version being unmaintainable horror show, etc.

Thanks for the write up, that's helpful. I saw that you mentioned you used jquery rather than flux. Is it too late for that now? Did you use reactjs.net (http://reactjs.net/)?

Uziel fucked around with this message at 13:35 on Nov 11, 2015

EssOEss
Oct 23, 2006
128-bit approved
Thanks for the interesting writeup! I will be doing some prototyping in the near future and this will serve as a good basis to make the technology decisions.

Meanwhile, does anyone here have experience with Windows Nano Server? I tried to get ASP.NET 5 running on it today but could not get anywhere due to DNVM PowerShell installer script actually requiring .NET Framework, which is... not available on Nano Server. Yet I see articles online about people using it, so I wonder if I am missing something.

Adbot
ADBOT LOVES YOU

Opulent Ceremony
Feb 22, 2012
Is there something about React I'm not understanding? It seems like the purposeful removable of 2-way data binding just means a lot more boilerplate code for common scenarios.

I'm imagining any sort of CRUD app whose purpose is to pull an entity from the DB and let someone make modifications to properties of it on the front-end, then eventually save it back. It seems like to do this with React, you need to make an event handler for every input field tied to a property so you can determine what to do with the change, whereas when I use Knockout, a little hooking up in the DOM and it keeps track of all the changes done on the front-end within a JS object, and then I can write a little function to serialize this object and send it to the server to be updated in the DB on a Save button click or something.

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