Better HN
topnewbestaskshowjobs
Log inSign up

algorithmsRcool

1,521 karma · joined May 25, 2012 (14y ago) · 286 submissions

https://github.com/AlgorithmsAreCool
Submissions

comment 2y ago · link · parent

C# these days is GREAT, but F# still has features that C# doesn't like unions and much more powerful (and ergonomic) pattern matching.

And line for line, F# is more effective at getting things done (and i would argue with less bugs)

comment 2y ago · link · parent

F# has been my favorite language since I first encountered it in uni. F# was/is waaaay out ahead of C# with features like unions, null safety, pattern matching, records, more powerful type inference and generic constraints.

Over the years C# has been implementing these features too, which is good, but they have been implementing them in incompatible ways, which isn't very good. Since the investment in F# has been much smaller than in C#, it hasn't been innovating as fast as C# and has been left behind in some ways.

But it is still a great language and remains broadly compatible with the ecosystem and can deliver equal performance to C# with far less boiler plate

comment 2y ago · link · parent

How much of a throughput penalty do those options incur on the application?

comment 2y ago · link · parent

It isn't trivial but it is supported. Here is an example [0] toy.

I am not aware of any production grade replacement GCs for .NET out there currently

https://github.com/kkokosa/UpsilonGC

comment 2y ago · link · parent

There is very little new under the sun. It reminds me of the wheel of time books, as the wheel turns we forget about the learnings of the previous age and reinvent them for ourselves. Often worse.

comment 2y ago · link · parent

> As for a delete operator, you can just roll your own struct based allocation framework that uses IDisposable to reclaim memory. But then you need to deal with all the traditional bugs like use-after-free and double-free and the like.

I forgot that there is built in support for this model using the MemoryManager<T> class [0]. A memory manager is an abstract class that represents a block of other memory, including possibly unmanaged memory. It implements IDisposable already so you can just plug into this.

The Memory<T> struct can optionally internally point to a MemoryManager instance allowing you to plug your perfered style of allocation and freeing of memory into parts of the framework.

There is a little irony that a MemoryManager<T> is itself a class and therefore managed on the gc-heap, but you can defeat this by using ObjectPool<T> to recycle those instances to keep allocation count steady state and not trigger the GC.

I have used this before (in the toy database i mentioned earlier) to allocate aligned blocks of unmanaged memory.

[0] https://learn.microsoft.com/en-us/dotnet/api/system.buffers....

comment 2y ago · link · parent

Ref-structs can also implement interfaces now too. The C# compiler team has been really delivering in this space the last few iterations

comment 2y ago · link · parent

Yes, this is what I meant

comment 2y ago · link · parent

> Because Anders Hejlsberg is one of the greatest language architects and the C# team are continuing that tradition.

I wish Anders was still in charge of C# :(

comment 2y ago · link · parent

>Anything that uses classes and interfaces will be memory managed by the GC...

Yes and no. Yes, almost all of the standard library collection are allocation heavy and it is still the dominate pattern in C#, so if you want to avoid the GC you need to avoid these and resort to building your own primitives based on Memory/Span. Which sucks.

However, you can use interfaces in a no GC world since you can constrain those interfaces to be structs or ref-structs and the compiler will enforce rules that prevent them from being boxed onto the GC heap.

Also of recent note, the JIT can now automagically convert simple gc-heap allocations into stack allocations if it can trivially prove they don't escape the stack context.

> It would be better if the GC can be turned off with a switch and just add a delete operator to manually free memory.

It is a little know fact that you can actually swap out the GC of the runtime. So you could plug in a null implementation that never collects (at your own peril...)

As for a delete operator, you can just roll your own struct based allocation framework that uses IDisposable to reclaim memory. But then you need to deal with all the traditional bugs like use-after-free and double-free and the like.

For me, I think low-gc is the happy medium. Avoid the heap in 99% of cases but let the GC keep things air tight

comment 2y ago · link · parent

Span and ref-like types enable massive changes to the way that memory is managed in C#. You can absolutely write almost GC-less code. I have been tinkering with a toy no-GC database engine in C# based on Direct I/O and some object pooling. I have been amazed at how far i can get before resorting to GC heap allocations

comment 2y ago · link · parent

This is where I fall back to Property Based Testing[0] and let the engine probe the high dimensional test space for me.

The test then becomes something like

  Check.Sample(
    Gen.Bool, Gen.Bool, Gen.Bool 
    (loggedIn, hasGreenHair, likesBananas) => { 
      var anyTrue = loggedIn | hasGreenHair | likesBananas;//the property to test
      var messagePrinted = formatMessage(loggedIn, hasGreenHair, likesBananas);

      Assert.Equal(anyTrue, messagePrinted);
    }
  );
This is obviously overkill for a test space of cardinality 8. But for complex cases this can provide better coverage of unexpected interactions than just stabbing a few positive and negative results.

Another approach for this test would be to use a metamorphic property (also possible with CsCheck). You basically come up with a rule that says something like, "if a user is logged in, then it should not matter if they have green hair or if they are like bananas". Then just let the framework search for falsifiable cases.

A real-world example of this was when I designed a scheduling system that would compile a set of abstract rules down to concrete events. I used metamorphic testing to look for cases where "If I add a new rule to a calendar, the total observable complexity of the calendar should be greater than or equal to before" (the equal case is if the new rule was equivalent to an existing rule. This allowed me to ensure that the internal complexity wasn't dropping observable details.

[0] https://github.com/AnthonyLloyd/CsCheck

comment 2y ago · link · parent

`Get-CimInstance Win32_Processor` on Powershell Core

74.

Microsoft Orleans v8.2.0(github.com ↗)

2 points · by algorithmsRcool · 2y ago · discuss

75.

Introduction to Vectorization with Vector128 and Vector256(github.com ↗)

2 points · by algorithmsRcool · 2y ago · discuss

76.

CsCheck: Random Testing Library for C#(github.com ↗)

1 points · by algorithmsRcool · 2y ago · discuss

comment 2y ago · link · parent

I'm going to note also after digesting the article further that CsCheck has support for "stateful"/"model-based" testing in addition to property-based testing. It also supports the linearizable/parallel testing that is described in the article.

See: - https://github.com/AnthonyLloyd/CsCheck?tab=readme-ov-file#m... - https://github.com/AnthonyLloyd/CsCheck?tab=readme-ov-file#c...

comment 2y ago · link · parent

For my C#/.NET testing I've been using CsCheck[0] and I've enjoyed it quite a bit. It was a lot more approachable compared to Hedgehog and FsCheck and is also quite fast.

[0] https://github.com/AnthonyLloyd/CsCheck

79.

What's New in C# 13(learn.microsoft.com ↗)

13 points · by algorithmsRcool · 2y ago · 2 comments

comment 2y ago · link · parent

I've found the DX of Dafny to be very approachable. The VSCode extension is pretty great, and you get feedback as you type. Also, its ability to give you counter examples in the IDE is really nice.

comment 2y ago · link · parent

Always cool to see Dafny mentioned!

Shameless plug: I just wrote a beginner's introduction to Dafny a few days ago.

https://www.linkedin.com/pulse/getting-started-dafny-your-fi...

82.

Hysteresis effect on threadpool hill-climbing(github.com ↗)

2 points · by algorithmsRcool · 5y ago · discuss

comment 5y ago · link · parent

> Putting more than 1M rows of data into Excel is not possible, and once you get into the low 100K's, it becomes almost unbearable.

I dispute this. Yes, the normal spreadsheet view of excel will buckle under 1M rows, but excel has another feature called "Power Pivot" that is backed by an embedded database and scales into the high millions at least.

I've personally used excel on a dataset of 18M rows and PowerPivot handled it just fine.

[0] https://support.office.com/client/Data-Model-specification-a...

[1] https://support.office.com/client/power-pivot-powerful-data-...

comment 6y ago · link · parent

Since it looks like they hit the spreadsheet row limit, this is a friendly reminder that the "Data Model" or "Power Pivot" mode [1] of excel scales far beyond [2] the spreadsheet mode.

[1] https://support.office.com/client/power-pivot-powerful-data-...

[2] https://support.office.com/client/Data-Model-specification-a...

comment 6y ago · link · parent

Part of the Trill[0] processing engine in C# does this. It uses reflection to vectorize normal objects into a columnar format internally.

[0] : https://github.com/microsoft/Trill

comment 6y ago · link · parent

I don't understand this mentality. Git itself doesn't provide a way to interact with PRs or issues on GitHub.

This utility does.

If you are uncomfortable with using GH to manage issues and PRs you shouldn't probably shouldn't be using GH.

comment 6y ago · link · parent

GitHub is killing it with these features. I wonder how long Azure Repos will survive on it's own.

comment 6y ago · link · parent

It is ok, but I would not recommend it. It got off to a great start but I ran into problems/limitations with some fairly basic stuff.

I can't recall exactly what my issue was with it however, it has been a few months.

12345
10