News for hackers. Stuff that matters.
Re:So We've Got a Memory Leak by vbezhenar on Saturday May 11, 2024 @12:00PM (#40328931)
Go's defer works like RAII and does not introduce indentations.

    f := createFile("/tmp/defer.txt")
    defer closeFile(f)
    writeFile(f)
Re:So We've Got a Memory Leak by seabrookmx on Saturday May 11, 2024 @12:09PM (#40328979)
Even when the syntax does require indentation ("with" in python, "using" in C#) it's still pretty clean IMO.
Re:So We've Got a Memory Leak by david_allison on Saturday May 11, 2024 @01:28PM (#40329464)
Additionally, `using` no longer requires indentation in C#

https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Re:So We've Got a Memory Leak by seabrookmx on Saturday May 11, 2024 @03:47PM (#40330229)
TIL!

I just recently updated a few small services to C# 12 and there's a bunch of little niceties like this I'm finding (spread operator for instance).

Re:So We've Got a Memory Leak by pjmlp on Saturday May 11, 2024 @03:55PM (#40330281)
Using also no longer requires inheritance from IDispose, it suffices that the type does support Dispose pattern, which is great when coupled with extension methods.
Re:So We've Got a Memory Leak by HideousKojima on Saturday May 11, 2024 @01:32PM (#40329487)
Using no longer requires a new scope block in more recent versions of C#
Re:So We've Got a Memory Leak by valicord on Saturday May 11, 2024 @04:01PM (#40330310)
This misses the main benefit of RAII which is that you can't forget to close the file.
Re:So We've Got a Memory Leak by pjmlp on Sunday May 12, 2024 @06:15AM (#40333334)
While not perfect, static analysis takes care of that, in similar veins C and C++ devs reach out to them for the language flaws.
Re:So We've Got a Memory Leak by rcxdude on Monday May 13, 2024 @04:04AM (#40340828)
Defer and context managers are a pale approximation of RAII. They are constrained to lexical scope, as opposed to RAII which works with object lifetimes. And it's the latter case which is much more error prone than 'oops, I forgot to close a file I opened this function'.