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
Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

For VS For Mac, I highly encourage you to go into the preferences and look at the Behaviors and IntelliSense options



At lot of really useful options are turned off by default (As a certain someone doesn't seem to like them) that a Visual Studio for Windows user would normally expect. So it's useful to play around with them and see what best fits with your workflow.

In terms of IntelliSense, VS For Mac uses roslyn so anything VS for Windows shows, VS for Mac should show. For that enum, you could right click it it offer to fill in the switch.







Keyboard shortcuts may be different between Windows and Mac, owing a bit to the heritage of VS for Mac.

For crossplatform GUI frameworks, Eto.Forms is good if you like more programatic GUI design. Xamarin.Forms is great if you like working with XAML (which most WPF developers are), and it targets more platforms, including mobile.

You can also make native Mac applications with Xamarin.Mac, but it's not as straightforward as it is making a Windows application with WinForms, WPF, or UWP.

Adbot
ADBOT LOVES YOU

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
Thanks for those suggestions. I've changed my Behaviour + Intellisense bits.

As far as the right-click option, mine seems to be less useful.
https://imgur.com/Z1MHsJX

I found people talking about liking Rider, and I've got a JetBrains licence through my university so that sounds like a possible alternative, especially as I'm used to PyCharm.

Thank you for the suggestion of Eto. I have no experience of making GUI, or exposure to XAML, so neither of those ideas mean anything to me. A quick google however suggests Eto doesn't work with Rider.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Sad Panda posted:

As far as the right-click option, mine seems to be less useful.
https://imgur.com/Z1MHsJX

Right click on "switch" instead of the variable. It should also show this if you click on "switch" and hover over the red line.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
Thank you! I'm a moron. That's pretty magical that it can bounce from switch to if and from foreach to for to while to dowhile.

Careful Drums
Oct 30, 2007

by FactsAreUseless

EssOEss posted:

What I would prefer to do is to zip the files on the fly to a temporary Azure blob. That is, do not write to filesystem, do not write to a MemoryStream in RAM, just append the data directly to the blob. This avoids using significant server resources besides the CPU and limits the range of things that can go wrong. Once the write is finished, give the user a SAS token enabled link to the blob and get rid of the blob after N hours.

I do not know if this processing model works well with the Zip and Azure Storage APIs, however. I am also unsure if the ZIP file format is friendly to append-only construction.

After riding the struggle bus directly downloading .zips from web api endpoints I gave this sort of solution a spin and I think it's going to work out much better. I'm going to have our web api generate the zip, store it in blob storage, and send a link to the blob to the client so the user can do what they want with it. It's a nice benefit that users can download the same zip twice without doing any duplicated computation. storage is cheap as hell, after all.

The built in ZipArchive class seems to be working fine with constructing the files in-memory and streaming up to blob storage, I was just misunderstanding things when I first posted about it.

Thanks programmer goons :)

e: also much easier to implement client-side

code:
<a href={blob_storage_uri} target="_blank">Click here to download your crap></a>

Careful Drums fucked around with this message at 16:00 on Jul 20, 2018

bobua
Mar 23, 2003
I'd trade it all for just a little more.

I want to make sure I understand something correctly.

In asp.net MVC, I've got a class that acts as a layer between my controllers and EF. All methods are static, and I use this bit of code for the db context...

code:
 public static ApplicationDbContext DB
        {
            get
            {
                if (HttpContext.Current.Items[DataProviderContextKey] == null)
                {
                    HttpContext.Current.Items[DataProviderContextKey] = new ApplicationDbContext();
                }
                return (ApplicationDbContext)HttpContext.Current.Items[DataProviderContextKey];
            }
        }
As I understand it, I'm not maintaining a single context. If 10 people are accessing the site, the fact that these are static isn't limiting their concurrency in any way... right?

Dietrich
Sep 11, 2001

You really should be injecting a DB context into your controller from a DI container that can maintain scope.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

Is there an advantage to di with a super small project? I've never implemented it, so I don't know what sort time it takes realistically.

Dietrich
Sep 11, 2001

The smaller the project the easier it is to do, and knowing how to do it will be very helpful for larger projects.

raminasi
Jan 25, 2005

a last drink with no ice

bobua posted:

Is there an advantage to di with a super small project? I've never implemented it, so I don't know what sort time it takes realistically.

You will probably have to spend some time learning whatever framework you choose, but once you know how it works then setting up simple stuff is practically free.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

bobua posted:

I want to make sure I understand something correctly.

In asp.net MVC, I've got a class that acts as a layer between my controllers and EF. All methods are static, and I use this bit of code for the db context...

code:
 public static ApplicationDbContext DB
        {
            get
            {
                if (HttpContext.Current.Items[DataProviderContextKey] == null)
                {
                    HttpContext.Current.Items[DataProviderContextKey] = new ApplicationDbContext();
                }
                return (ApplicationDbContext)HttpContext.Current.Items[DataProviderContextKey];
            }
        }
As I understand it, I'm not maintaining a single context. If 10 people are accessing the site, the fact that these are static isn't limiting their concurrency in any way... right?

You don't want to have a single context, ideally you'd have a per-request context.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I'm strugging with some weird database stuff. I'm attempting to run a query, do some stuff to the results, and return them. Standard stuff. But the query I'm running returns a large dataset (several hundred thousand records). The query itself executes incredibly quickly in DataGrip, but when I run the query in C# it's incredibly slow. I originally thought maybe it was Dapper's mappings that were taking forever, so I went straight to the database using NpgsqlConnection and NpgsqlCommand and still it takes a huge amount of time. Are there any tricks to reading a large dataset from a database in C# that I can use to speed things up?

Mr Shiny Pants
Nov 12, 2012

a hot gujju bhabhi posted:

I'm strugging with some weird database stuff. I'm attempting to run a query, do some stuff to the results, and return them. Standard stuff. But the query I'm running returns a large dataset (several hundred thousand records). The query itself executes incredibly quickly in DataGrip, but when I run the query in C# it's incredibly slow. I originally thought maybe it was Dapper's mappings that were taking forever, so I went straight to the database using NpgsqlConnection and NpgsqlCommand and still it takes a huge amount of time. Are there any tricks to reading a large dataset from a database in C# that I can use to speed things up?

Anything specifically slow? Getting the records? Getting the query to the server?

SirViver
Oct 22, 2008
Assuming DataGrip works like every other (worthwhile) SQL IDE, executing a query won't actually fetch all results immediately. In fact, a quick search reveals the Result Set Prefetch Size setting, which is likely what tricks you into thinking retrieving the query results actually completes that fast. Try clicking the "go to last page" button in DataGrip and see how long it actually takes.

My guess is the performance will now look more comparable. Speeding things up from this point on requires actual profiling to see where the bottleneck is (network? disk? memory?). However, it might be more practical to reconsider if you actually need all that data in memory in the first place, which depends on what you need to do with it. The final result may just be accepting that processing that amount of data simply takes a while - it really also depends on just how slow you're talking about here.

SirViver fucked around with this message at 10:01 on Aug 2, 2018

EssOEss
Oct 23, 2006
128-bit approved
Also good (though not necessarily relevant in this case) reading on the topic: http://www.sommarskog.se/query-plan-mysteries.html

LongSack
Jan 17, 2003

Something I ran across today, which I present for your edification/amusement/complete apathy.

I have had issues in the past where closing the main window does not terminate the application. Never been able to puzzle out why, no unclosed windows, so it’s something else. Because of this, in the method that actually closes my application, I got into the habit of calling Environment.Exit(0) as a final step.

Working on a new app today, I did the same thing, except that I forgot to call Application.Current.MainWindow.Close() before calling Environment.Exit.

As a result, if I ran the application and pressed the exit button (or hit Escape), everything worked as expected, and the debugger showed that the program exited with code 0. However, if I alt-tabbed to another app, or if the program main window lost focus for any reason, Environment.Exit actually threw an exception.

I have no clue why losing focus would cause this, and it was corrected by closing the main window before calling Environment.Exit.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I don't know the first thing about developing desktop apps, but it seems logical to me that exiting the app would be a distinctly different operation than closing the window and it doesn't surprise me that you need to do both. But again, I don't know anything about desktop stuff.

EssOEss
Oct 23, 2006
128-bit approved
Most desktop apps tend to just have a "DoMainWindowStuff()" as the last call in their entry point, so it makes sense for that window closing to end the app. The situation above sounds like an interesting mystery deserving of more investigation, though! Share some repro!

Collateral Damage
Jun 13, 2009

iirc for windowed applications you should use Application.Exit() rather than Environment.Exit().

LongSack
Jan 17, 2003

EssOEss posted:

Most desktop apps tend to just have a "DoMainWindowStuff()" as the last call in their entry point, so it makes sense for that window closing to end the app. The situation above sounds like an interesting mystery deserving of more investigation, though! Share some repro!

The exception thrown is:
code:
Exception thrown at 0x75547918 (msctf.dll) in OGTool.exe: 0xC0000005: Access violation writing location 0x00000000.
Not sure what msctf.dll is, there is scant information about it, but it appears to be writing to a null pointer.

The real mystery is why is there a difference between when the window has lost focus (the above exception occurs), and when the window has never lost focus (process terminates with return code 0).

Alas, my search ends here, as there are no further paths to explore, and the fix is to close the window before exiting.

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick

LongSack posted:

I have had issues in the past where closing the main window does not terminate the application. Never been able to puzzle out why, no unclosed windows, so it’s something else. Because of this, in the method that actually closes my application, I got into the habit of calling Environment.Exit(0) as a final step.

Typically, this happens if you still have another thread running in your process. Windows doesn't treat the UI thread differently to any other threads running in your process, so just because all your windows have been closed doesn't imply that Windows should end your process. You should see the other threads in the debugger in VS and figure out where they came from and why they weren't shut down before you closed your application's main window. If you're cleaning up your resources correctly, you shouldn't have to call Environment.Exit(0) in order to force your process to end.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

LongSack posted:

Not sure what msctf.dll is, there is scant information about it

It's the client side of Text Services Framework, which provides advanced text input features

LongSack
Jan 17, 2003

beuges posted:

If you're cleaning up your resources correctly, you shouldn't have to call Environment.Exit(0) in order to force your process to end.

Agreed, it’s down to laziness on my part, where if the cause wasn’t immediately obvious, I was like “welp, gently caress it ... Environment.Exit()”

I understand a lot more about WPF than I did then, so I think I will get out of the habit of doing that, since - by definition - if closing the main window doesn’t end the application I’ve done something wrong. (Yes, I know there are situations where you might deliberately choose to do something else when the main window closes.)

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
We use a library called RazorLight in one of our projects to render Razor strings to HTML strings. This has been working well enough up until our recent transition to .NET Core 2.1 from .NET Core 2.0. For some reason we're now getting a huge exception that basically says (in my interpretation) none of the core library stuff can be found:

RazorLight.Compilation.TemplateCompilationException: Failed to compile generated Razor template:
- (3:35) The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (3:63) Predefined type 'System.String' is not defined or imported
- (3:79) Predefined type 'System.Type' is not defined or imported
- (3:10) Predefined type 'System.Void' is not defined or imported
- (7:69) Predefined type 'System.Boolean' is not defined or imported
- (7:37) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (10:66) The return type of an async method must be void, Task or Task<T>
- (10:61) The type name 'Task' could not be found in the namespace 'System.Threading.Tasks'. This type has been forwarded to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' Consider adding a reference to that assembly.
- (10:66) 'GeneratedTemplate.ExecuteAsync()': return type must be 'Task' to match overridden member 'TemplatePageBase.ExecuteAsync()'
- (10:66) The type 'Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (12:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (12:12) Predefined type 'System.Object' is not defined or imported
- (12:25) Predefined type 'System.Int32' is not defined or imported
- (12:28) Predefined type 'System.Int32' is not defined or imported
- (12:31) Predefined type 'System.Boolean' is not defined or imported
- (12:12) Predefined type 'System.Void' is not defined or imported
- (13:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (13:12) Predefined type 'System.Object' is not defined or imported
- (13:25) Predefined type 'System.String' is not defined or imported
- (13:12) Predefined type 'System.Void' is not defined or imported
- (14:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (14:12) Predefined type 'System.Object' is not defined or imported
- (14:12) Predefined type 'System.Void' is not defined or imported
- (15:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (15:12) Predefined type 'System.Object' is not defined or imported
- (15:25) Predefined type 'System.Int32' is not defined or imported
- (15:28) Predefined type 'System.Int32' is not defined or imported
- (15:32) Predefined type 'System.Boolean' is not defined or imported
- (15:12) Predefined type 'System.Void' is not defined or imported
- (0:2) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (0:2) Predefined type 'System.Object' is not defined or imported
- (0:2) Predefined type 'System.Void' is not defined or imported
- (21:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (21:12) Predefined type 'System.Object' is not defined or imported
- (21:12) Predefined type 'System.Void' is not defined or imported
- (22:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (22:12) Predefined type 'System.Object' is not defined or imported
- (22:25) Predefined type 'System.Int32' is not defined or imported
- (22:29) Predefined type 'System.Int32' is not defined or imported
- (22:33) Predefined type 'System.Boolean' is not defined or imported
- (22:12) Predefined type 'System.Void' is not defined or imported
- (23:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (23:12) Predefined type 'System.Object' is not defined or imported
- (23:25) Predefined type 'System.String' is not defined or imported
- (23:12) Predefined type 'System.Void' is not defined or imported
- (24:12) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (24:12) Predefined type 'System.Object' is not defined or imported
- (24:12) Predefined type 'System.Void' is not defined or imported
- (10:66) 'GeneratedTemplate.ExecuteAsync()': not all code paths return a value
- (7:17) Predefined type 'System.Void' is not defined or imported

See CompilationErrors for detailed information

at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)
--- End of stack trace from previous location where exception was thrown ---
at RazorLight.Compilation.TemplateFactoryProvider.CompileAsync(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.TemplateFactoryProvider.CreateFactoryAsync(String templateKey)
at RazorLight.RazorLightEngine.CompileTemplateAsync(String key)
at RazorLight.RazorLightEngine.CompileRenderAsync(String key, Object model, Type modelType, ExpandoObject viewBag)


Does anyone know what would be causing this?

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

a hot gujju bhabhi posted:

:words:

Does anyone know what would be causing this?

Seems like this GitHub issue fits the bill. Seems multiple people have "workarounds" but the issue is still open.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Drastic Actions posted:

Seems like this GitHub issue fits the bill. Seems multiple people have "workarounds" but the issue is still open.

I did find that, but none of the suggestions seemed to help.

The problem is when I try it in a console app it works just fine. It's something related to this project I think - to clarify: it's being used in a class library that is in turn being used in an MVC project. All of our projects are targetting .NET Core 2.1.

LongSack
Jan 17, 2003

hackbunny posted:

It's the client side of Text Services Framework, which provides advanced text input features

Interesting. Would this be related to the fact that I have a Russian language keyboard installed?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

a hot gujju bhabhi posted:

I did find that, but none of the suggestions seemed to help.

The problem is when I try it in a console app it works just fine. It's something related to this project I think - to clarify: it's being used in a class library that is in turn being used in an MVC project. All of our projects are targetting .NET Core 2.1.

I should also mention we're using Linux Docker containers, but as far as I can tell that makes no difference - the console app also works when run within a docker container running the same image as our other project.

qsvui
Aug 23, 2003
some crazy thing
Hello thread, I discovered I have to suddenly learn C# for work in order to develop Windows programs and I was wondering if there are any recommended books. I am already familiar with programming in C and C++, but I have never written code for Windows and I have no idea what .NET is.

I would also appreciate feedback on recommended unit testing frameworks and practices. The OP mentioned some information about these but it looks like it hasn't been updated in a while so I just wanted to be sure.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

qsvui posted:

Hello thread, I discovered I have to suddenly learn C# for work in order to develop Windows programs and I was wondering if there are any recommended books. I am already familiar with programming in C and C++, but I have never written code for Windows and I have no idea what .NET is.

I would also appreciate feedback on recommended unit testing frameworks and practices. The OP mentioned some information about these but it looks like it hasn't been updated in a while so I just wanted to be sure.

Are you talking about Windows desktop applications? Are these greenfield or are you maintaining existing applications?

Fundamental unit testing practices haven't changed much in recent years. XUnit / NUnit are still excellent testing frameworks that are widely used. MSTest had "v2" open-source rebirth recently and it's fine, too. The Art of Unit Testing is still my go-to recommendation.

LongSack
Jan 17, 2003

qsvui posted:

Hello thread, I discovered I have to suddenly learn C# for work in order to develop Windows programs and I was wondering if there are any recommended books. I am already familiar with programming in C and C++, but I have never written code for Windows and I have no idea what .NET is.

I would also appreciate feedback on recommended unit testing frameworks and practices. The OP mentioned some information about these but it looks like it hasn't been updated in a while so I just wanted to be sure.

For C# itself, as a reference work, I highly recommend this book, although I must stress that it is a reference and not a tutorial. For WPF, check out this book, which I found helpful.

Edit: for a tutorial, try this book.

Second edit: if you are not familiar with the MVVM model, learn it and use it - just my humble opinion, of course.

LongSack fucked around with this message at 05:04 on Aug 7, 2018

qsvui
Aug 23, 2003
some crazy thing

New Yorp New Yorp posted:

Are you talking about Windows desktop applications? Are these greenfield or are you maintaining existing applications?

I believe I will be working on new desktop applications.

LongSack posted:

For C# itself, as a reference work, I highly recommend this book, although I must stress that it is a reference and not a tutorial. For WPF, check out this book, which I found helpful.

Edit: for a tutorial, try this book.

Second edit: if you are not familiar with the MVVM model, learn it and use it - just my humble opinion, of course.

Thanks for the suggestions!

LongSack
Jan 17, 2003

qsvui posted:

I believe I will be working on new desktop applications.


Thanks for the suggestions!

I linked the wrong book for the tutorial (not that that book is necessarily bad, but it's not the book I was thinking of). I meant to link this book.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

LongSack posted:

Interesting. Would this be related to the fact that I have a Russian language keyboard installed?

Nah, Russian is one of the easy ones, just a key map for your keyboard. Text Services is there on the off-chance you need to input, say, Japanese, or provide text to an external spell-checker or dictionary lookup, stuff like that (not that I've ever seen any of that stuff on Windows, compared with macOS). Once upon a time, you had three layers of complexity to text input in Windows: simple keyboard layouts, built into Win32, which are good for the vast majority of languages in the world; Input Method Manager (IMM), to support input methods that don't fit on a standard PC keyboard (originally and notably, Chinese, Japanese and Korean writing); and Text Services Framework, which is extremely complex and a huge superset of IMM (fully bidirectional instead of input-only, supports rich text, etc.). You used to have to go out of your way to even load IMM and TSF, but I think nowadays even the standard Edit control from Common Controls has full support, so it would make sense that WPF enabled it by default, too. In a world where even Notepad loads it, you should make peace with it

hackbunny fucked around with this message at 00:44 on Aug 9, 2018

LongSack
Jan 17, 2003

hackbunny posted:

interesting information

Thanks!

Magnetic North
Dec 15, 2008

Beware the Forest's Mushrooms
This is sort of an odd question but it keeps popping up: Why is Virtual a thing? I learned in Java so all you had to do was override the method. Everything was 'virtual' in that way. I can understand the use of having sealed to disallow it, but I don't understand the reason for it allowing 'hiding' or whatever it does if you give a child class an override with the same name as an inherited non-virtual method. I'm sure there is a reason.

mystes
May 31, 2006

Magnetic North posted:

This is sort of an odd question but it keeps popping up: Why is Virtual a thing? I learned in Java so all you had to do was override the method. Everything was 'virtual' in that way. I can understand the use of having sealed to disallow it, but I don't understand the reason for it allowing 'hiding' or whatever it does if you give a child class an override with the same name as an inherited non-virtual method. I'm sure there is a reason.
There's probably no reason c# really has to make you do this (I have no idea how the CLR actually works but I assume it's complicated), but this convention is a holdover from C++.

In C++, method are normally just functions with addresses that are determined at compile time (and the object is just like an extra hidden argument). This means that you normally don't have dynamic dispatch: you could shadow methods in the subclasses to hide and sort of fake override them (I assume) but the compiler has to be able to determine which function to call at compile time.

If you want dynamic dispatch (so you don't need to know which subclass an object is an instance is when you call a method), you mark the method as virtual. In this case, rather than using a function that's determined at compile time, it uses a vtable (an array of function pointers). Instances have a pointer to the proper vtable, and when you call the virtual method it actually indexes into the vtable at runtime to figure out which function to run.

EssOEss
Oct 23, 2006
128-bit approved
I would say the main reason is intent. You are not supposed to derive from a class unless the author of that class intends you to do so. You are not supposed to override a method unless the author of that method intends for it to be overridden. Extending code that was not meant to be extended is a recipe for creating large piles of garbage code. The virtual keyword is the way that the author can signal this intent to the compiler. The sealed keyword is the equivalent for deriving from a class, though unfortunately it works the wrong way around (it should instead be "extensible" or such, with default being sealed).

biznatchio
Mar 31, 2001


Buglord
Yeah, virtual is a very important part of a class's contract and shouldn't just blindly be applied to everything in the way Java normally does. As a base class, making a method virtual means that you can't rely on it doing what you expect it to do in derived classes. Consider the following example:

code:
    public class BaseClass
    {
        public BaseClass(IMyDAL dal, UserToken currentUser)
        {
            _dal = dal;
            _currentUser = currentUser;
        }

        private readonly IMyDAL _dal;
        private readonly UserToken _currentUser;

        public bool CheckAccess(string resource)
        {
            return _dal.CheckAccess(_currentUser, resource);
        }

        public void KillEverything()
        {
            if (!CheckAccess("LaunchMissiles"))
                throw new AccessDeniedException();

            _dal.EndHumanity();
        }
Non-virtual methods by default like in C#? No problem. But if you presume everything is virtual by default like in Java, then this happens:

code:
        public class DerivedClass: BaseClass
        {
            public DerivedClass(IMyDAL dal, UserToken currentUser)
                : base(dal, currentUser)
            {
            }

            public override bool CheckAccess(string resource)
            {
                return true;
            }
        }
Next thing you know your biggest concern is avoiding radscorpions and finding a new water chip; all because you left a critical method virtual and someone derived from your class and broke it, and thus violated your encapsulation. Basically, you have to defensively assume that every non-final/sealed method isn't going to do at all what you intended it to do.

Allowing people to break your assumptions is something you should always be opting into (by adding a keyword to allow it), not out of (by adding a keyword to disallow it).

Adbot
ADBOT LOVES YOU

epswing
Nov 4, 2003

Soiled Meat
In Visual Studio 2015, if I have a class which doesn't inherit anything



It looks like this in the solution explorer



But if I subclass e.g. WebClient



It looks like this in the solution explorer (the icon has changed)



When I double-click the file, it opens in Design view. This is not what I want.



The design view provides a link to "add components to my class". Is this because WebClient is a subclass of Component?

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