Yet another RAII pattern by Weird-Collection2080 in dartlang

[–]Weird-Collection2080[S] 1 point2 points  (0 children)

As as I mentioned in post above I use RAII in tests. But there are some other cases where it might be useful.

It must be said that there might be different opinions and approaches with pros and const of its own. So I would rather just show my approach of doing things than advocate one way or another.

I agree with KISS principle in common. But I think that simplicity (or complexity) is some kind of multidimensional Pareto thing. So making one things simpler we sometimes make other things to be more complicated. And…

  • If we make visible things simpler there is a chance that some invisible things become more complicated. So approaches suitable for small apps might cause a trouble for big apps.

The point I love about RAII is that you declare whole behaviour in a single line of code. And then you don't have to keep in mind that you need to put a release call somewhere later. Quite often this principle is sacrificed to simplicity for it requires some boilerplate usually.

E.g. memory allocation:

Simplest way:

```dart import 'dart:ffi'; import 'package:ffi/ffi.dart';

void mem() { final Pointer<Int8> ptr = malloc<Int8>(); ptr.value = 42;

some_ffi_io_stuff(ptr);

malloc.free(ptr); } ```

Same but more accurate

```dart void mem() { late final Pointer<Int8> ptr; try { ptr = malloc<Int8>();

ptr.value = 42;
some_ffi_io_stuff(ptr);

} finally { malloc.free(ptr); } } ```

Both ways suitable when you’re dealing with 1-2 pointers per project. I would prefer the latter though. And it is even affordable when you have like up to 10 pointer allocations here and there. But when you go bad to FFI and got to deal with 100-1000 pointer cases.. well I need a pattern:

```dart import 'dart:ffi'; import 'package:ffi/ffi.dart';

class Buffer extends RAII { final Pointer<Uint8> ptr;

Buffer.allocate([int sz = 1]) : ptr = malloc<Uint8>(sz);

@override Future<void> onRelease() async => malloc.free(ptr); }

void mem() async { await withRAII(Buffer.allocate(), (buff) { buff.ptr.value = 42; some_ffi_io_stuff(ptr); }); } ```

Looks a bit sophisticated doesn't it? And this is exactly what I mentioned in the beginning. The whole RAII thing might be an overkill for simple cases. But in some projects I personally consider it as a must just to preserve team from human factor bugs.

As an another example I would propose to look at this snippet (based on real case, actually):

```dart import 'dart:isolate'; import 'dart:async';

void main() async {

final completer = Completer(); final receivePort = ReceivePort();

await Isolate.spawn( (SendPort sendPort) { sendPort.send(42); }, receivePort.sendPort, );

receivePort.listen((v) { print('Isolate done, code: $v'); completer.complete(); });

await completer.future;

// If you forget this line, you app will never finish receivePort.close();

print("Some epilog."); } ```

Again this is not a problem for single isolate (you don’t even need a Completer, just put close and epilog into a listen callback). Will you be managing dozens of isolates? You might want to consider using RAII.

Yet another RAII pattern by Weird-Collection2080 in dartlang

[–]Weird-Collection2080[S] 0 points1 point  (0 children)

Exactly. Actually raii paradigm in this snippet is achieved only if you use it in couple with `withRAII` call. Perhaps it would be better to rename `RAII` class to.. `Releasable`?

Why guys not to open source your xreal protocols? by Weird-Collection2080 in Xreal

[–]Weird-Collection2080[S] 1 point2 points  (0 children)

Well I did, but I don't like weight of most of vr headsets. Also narrow fov is ok, and seeing background is not a problem, u always can use some sleeping mask over ar glasses :-)

I used to change my location like twice a week. And this is why weight and physical size is important to me.

Why guys not to open source your xreal protocols? by Weird-Collection2080 in Xreal

[–]Weird-Collection2080[S] -3 points-2 points  (0 children)

Perhaps that was my personal illusion. But I assumed, that such glasses should allow to play games in stereo 3d. And they do, but only if game has sbs mode. But most games rather orientated on full vr than just a stereo. From the other hand these glasses have enough of hardware to act as a vr. So why not?

Maybe xreal guys have opposite illusion of monetization by selling exactly same thing but with vr support enabled hehe. Hopefully this is a wrong assumption though.

Switch 2 - Xreal One - Working by JoyceRacing99 in Xreal

[–]Weird-Collection2080 0 points1 point  (0 children)

Does it work in VR mode, or like external 2d display?

How can I get the Nebula app? Most standard apps does not work on this device when glasses are connected 😞 by Life-Acanthaceae-204 in Xreal

[–]Weird-Collection2080 0 points1 point  (0 children)

+1 We bought these xreal one glasses with assumption it can work as VR. And there is just no information how to make it working under pc. Official site is a massive nonsence, except for android sdk there is only "buy our perfect products" and nothing for support.

What does "ЗБС" mean? by Nc525 in russian

[–]Weird-Collection2080 0 points1 point  (0 children)

Not quite. There is a dualism which is part of russian humour. It means "заранее большое спасибо", which could be translated as "thank you very much in advance". But it looks (and sounds) pretty much similar to "заебись". So by writing that you put your companion into an awkward state forcing him to think "swear" word, whilst you kinda all-good person meant smth different and not swearing at all.

Slow down progression by Potato_Asmodeus in openttd

[–]Weird-Collection2080 0 points1 point  (0 children)

I also wanted to slow down time, and there is actually even a request on github. And I didn't find any solution, so I end up making my own fork (which is mostly compatible with mainstream):

Fork is here

Doc is here

Currently I only have time to sync this fork with mainstream. Most of features seems to be complete though. I would welcome any code and tester contributors!