News for hackers. Stuff that matters.
Re:Memory usage of a toy C# server and client with 500K conc... by nicoburns on Saturday January 26, 2019 @04:43PM (#19008696)
I think C# is underrated because it was closed source for so long, and working with a closed source ecosystem is such a pain (and risky!). At least personally, that made C# a complete non-starter for me before. However, I've recently started learning it, and it really is nice. It's much more pleasant to work with than Java.

Hopefully it will see a renaissance when people realise that with ASP.Net Core they can write code that looks broadly similar to Rails/Laravel/Django code, and get much better performance more or less for free. There are definitely some rough edges around the ecosystem though. Entity Framework isn't nearly nice as Laravel's Eloquent ORM, and it's pretty jarring looking at a promising library, only to realise that it's a commercial offering (don't get that with PHP!).

Re:Memory usage of a toy C# server and client with 500K conc... by cbHXBY1D on Saturday January 26, 2019 @05:30PM (#19008966)
Not to mention the recent performance gains from adding Span<T> in .NET Core 2.1.

I've used F# in a few professional projects before and that language is certainly underrated. I used to work in Microsoft's DevDiv and everyone knew it was criminally underfunded. I think if it had OCaml-style modules and Microsoft threw more weight behind it could take off big time.

Re:Memory usage of a toy C# server and client with 500K conc... by nicoburns on Saturday January 26, 2019 @05:49PM (#19009070)
Indeed, it was learning Rust that led me to being interested in learning C#, and Span<T> is basically the equivalent of Rust's &[T] slices, which are super useful for avoiding copies. It's pretty cool that C# has things like these and stack-allocated structs, which let me carry over a lot of the performance optimizations I might use in Rust.
Re:Memory usage of a toy C# server and client with 500K conc... by AdeptusAquinas on Sunday January 27, 2019 @03:40AM (#19010925)
Adding it to dotnet core by default certainly helps I think. I didn't start learning it until recently, but when I did having it part of the tools I use every day was awesome.
Re:Memory usage of a toy C# server and client with 500K conc... by platz on Saturday January 26, 2019 @07:48PM (#19009612)
Don Syme will never allow ocaml-style modules
Re:Memory usage of a toy C# server and client with 500K conc... by Scramblejams on Sunday January 27, 2019 @02:13AM (#19010697)
Why not?
Re:Memory usage of a toy C# server and client with 500K conc... by clausok on Monday January 28, 2019 @10:36AM (#19018210)
Don Syme, on omitting ocaml-style modules from F#:

In addition, there was the question what not to implement. A notable omission from the design was the functorial module system of OCaml. Functors were a key part of Standard ML and a modified form of the feature was included with OCaml, a source of ongoing controversy amongst theoreticians. The author was positively disposed towards functors as a “gold standard” in what parameterization could be in a programming language but was wary of their theoretical complexities. Furthermore, at the time there were relatively few places where functors were used by practicing OCaml programmers. One part of the OCaml module system – nested module definitions – was eventually included in the design of F#. However, functors were perceived to be awkward to implement in a direct way on .NET and it was hard to justify their inclusion in a language design alongside .NET object programming.

The Early History of F# https://fsharp.org/history/hopl-draft-1.pdf

Re:Memory usage of a toy C# server and client with 500K conc... by dunefox on Sunday January 27, 2019 @06:09AM (#19011274)
I think it might make interop harder.
Re:Memory usage of a toy C# server and client with 500K conc... by twodave on Saturday January 26, 2019 @08:21PM (#19009794)
If you’re not happy with EF, and don’t mind writing your own SQL, give Dapper a try. I’ve used a variety of SQL ORMs in C# over the last 12 years, but they always seem to fall short for me in some way. I like to be in control and also have nice types, and Dapper is the perfect answer for that.

Yes, you do end up writing some code that a great ORM would just give you for free, but honestly I haven’t felt pain from doing this as it makes me actually think about and set in stone what relationships and models I intend to support in my data layer.

Re:Memory usage of a toy C# server and client with 500K conc... by zoeysaurusrex on Saturday January 26, 2019 @08:54PM (#19009917)
Or better yet, don’t fall for the monotoolism trap and use both! I regularly use EF for inserting lots of hierarchy using one transaction, and dapper for fast view/materialized view reads. It’s an excellent combination.
Re:Memory usage of a toy C# server and client with 500K conc... by twodave on Saturday January 26, 2019 @09:25PM (#19010032)
Sure, and then there’s of course old school ADO.NET for bulk inserts.
Re:Memory usage of a toy C# server and client with 500K conc... by tracker1 on Sunday January 27, 2019 @10:58PM (#19015248)
One of the main projects I'm working on is using JSON for a more normalized usage of stored procedures with MS-SQL `method(tokenJSON, inputJSON, out outputJSON, out outerrJSON)`, so using Straight ADO.Net for most calls and responses. I'm not a fan of DB heavy logic, but it has made the API layer super thin and works pretty well.
Re:Memory usage of a toy C# server and client with 500K conc... by nicoburns on Saturday January 26, 2019 @08:54PM (#19009919)
I find writing raw SQL to be quite annoying for simple CRUD operations. It's just so easy to make stupid little syntax mistakes when writing SQL. And things like having to update all your queries if you add a column to your database are pretty annoying too...

ORM's like Eloquent (PHP) are super nice, because they let you lean on them completely for simply queries, and then give you layers of opt-outs. For example, inserting a row is just obj->save(). For slightly tricky selects you can use the whereRaw method to interpolate raw SQL into just a where clause of the query, or you can use DB::query() to write a full raw SQL query if you have some queries that are particularly complex.

I guess I could give Dapper a go though. SQL is... fine.

Re:Memory usage of a toy C# server and client with 500K conc... by wvenable on Sunday January 27, 2019 @12:33AM (#19010477)
I think you misunderstand Entity Framework if you think it's worse than Eloquent. Eloquest is ok and certainly pretty reasonable for PHP. But EF and Linq are in another ballpark entirely -- it's extremely easy to use and even allows you to do type-safe queries.
Re:Memory usage of a toy C# server and client with 500K conc... by nicoburns on Sunday January 27, 2019 @07:09AM (#19011406)
Perhaps! I'm new to .Net and Entity Framework.

But from what I can see, EF is trying to provide an abstraction layer that pretends that I am just working with collections of objects, which I don't like at all because it makes it harder to control which queries actually get executed and when!

On the other hand, Eloquent provides an abstraction for generating queries, but this maps pretty closely to SQL, and it otherwise largely stays out of the way...

The type safety is nice, and of course you don't get that in PHP. But IMO that's more about the language than the library.

Re:Memory usage of a toy C# server and client with 500K conc... by wvenable on Sunday January 27, 2019 @12:34PM (#19012713)
EF will only query exactly what you ask for and will execute the query only at the point you actually iterate or request an object. For changes, EF will only hit the database when you call SaveChanges() on the context. It's an abstraction that works with very few "leaks".

Eloquent also has object collections. Both frameworks have similar methods for filtering and querying. Eloquent is much more clunky (because PHP) and the underlying conceptual model is different (ActiveRecord style vs. DataMapper style). I certainly would use Eloquent for PHP projects but I definitely wish PHP could do something like EF.

Re:Memory usage of a toy C# server and client with 500K conc... by noir_lord on Sunday January 27, 2019 @01:05PM (#19012855)
Doctrine is closer (in terms of actually been a Data Mapper) than Eloquent so it may be more up your alley.
Re:Memory usage of a toy C# server and client with 500K conc... by twodave on Saturday January 26, 2019 @09:23PM (#19010031)
I mean, I get writing boilerplate SQL can be annoying, but honestly if you organize your code well then you end up making changes only in a few places (your repository class and wherever the new column actually gets used). By encapsulating your database in a set of repository classes you can avoid most headaches. Even if you don’t write your own SQL for most things, this is a really valuable pattern to follow in data-centric code of any kind.
Re:Memory usage of a toy C# server and client with 500K conc... by highace on Sunday January 27, 2019 @08:32AM (#19011605)
Look at Dapper.Contrib - it's an extension lib for Dapper that adds a load of ORM-esque functions for basic CRUDing.
Re:Memory usage of a toy C# server and client with 500K conc... by animal531 on Monday January 28, 2019 @08:47AM (#19017354)
Yeah, also Dapper.Extensions/Mapper/SimpleCRUD etc.

There are a lot of add-ons for it that simplifies all the generics for you.

Re:Memory usage of a toy C# server and client with 500K conc... by naasking on Sunday January 27, 2019 @09:24AM (#19011780)
> I find writing raw SQL to be quite annoying for simple CRUD operations. It's just so easy to make stupid little syntax mistakes when writing SQL.

There are ways to mitigate this [1]. You write your queries in .sql files in Visual Studio, so you get intellisense and syntax highlighting, and you can even add these to your automated test suite to ensure they run correctly.

[1] https://github.com/naasking/Dapper.Compose

Re:Memory usage of a toy C# server and client with 500K conc... by platz on Sunday January 27, 2019 @12:30PM (#19012684)
what is the benefit of "composing" queries via this library instead of just running them separately in a single connection? The "composed" queries are completely opaque to each other and are independent - they are not "composed", just "batched".
Re:Memory usage of a toy C# server and client with 500K conc... by naasking on Sunday January 27, 2019 @03:02PM (#19013493)
> what is the benefit of "composing" queries via this library instead of just running them separately in a single connection?

I think the link is pretty clear: it combines and batches queries while providing a type-safe interface for the returned results. It further provides intellisense and unit testing features that are tedious and error-prone to achieve in other ways.

Of course you can do this all by hand, or manually batch your queries to avoid round trips, but why would you want to?

Re:Memory usage of a toy C# server and client with 500K conc... by pjmlp on Sunday January 27, 2019 @04:14AM (#19011019)
Dapper is quite good middle ground.

The flexibility and performance of full SQL, without having to write all the mapping boilerplate by hand.

Re:Memory usage of a toy C# server and client with 500K conc... by benaadams on Saturday January 26, 2019 @06:22PM (#19009224)
Can blend the PHP and .NET Core ecosystems if you want: https://www.peachpie.io/
Re:Memory usage of a toy C# server and client with 500K conc... by NicoJuicy on Sunday January 27, 2019 @05:12AM (#19011153)
Re:Memory usage of a toy C# server and client with 500K conc... by kochthesecond on Sunday January 27, 2019 @04:16PM (#19013832)
I am a long term Java developer, but C# is looking really, really nice.

The eco system still seems wonky, but NuGet probably isnt more weird than that of Golang.

Re:Memory usage of a toy C# server and client with 500K conc... by tracker1 on Sunday January 27, 2019 @11:01PM (#19015256)
I'm not sure about now, but in the past every time I touched Java projects, it just seemed really wonky as well. I see a lot of that carries to the "enterprise" side of both areas. But will say C# was much easier to get a grasp of both with and without tooling for me.

NuGet, I'm still not sure of either, but at least it mostly works transparently. Though I haven't actually tried publishing anything to it, only consumed. npm seems to have the least resistance imho, for good and bad results alike.

Re:Memory usage of a toy C# server and client with 500K conc... by gregmac on Sunday January 27, 2019 @03:27AM (#19010892)
One of the first things you should do when you find a library that you are considering is look at the license. This applies to any language, and any type of software (commercial, open source, SaaS or not). Even for open source, not all open source licenses are compatible with each other (eg, you cannot use GPL in a MIT-licensed project).