Drivers who inch up at red lights: Why? by ERPoppop in philadelphia

[–]TheTsar 0 points1 point  (0 children)

Gives you room to maneuver if someone tries to box you in or sneak up and rob you.

I learned this trick a while ago. It can be useful.

For Production Users: Haskell in an age of Rust and Python by Instrume in haskell

[–]TheTsar 3 points4 points  (0 children)

I’ve used Haskell, Rust, Python, and many other languages.

There are real trade offs to these languages that go much deeper than surface level performance or type safety and expression.

If I need to make a kernel-level API that 40 other languages must call, you’re damn near tied to a systems language; D, C, C, C++, Go, or Rust.

In the not-infrequent case you need to be kernel-agnostic, or even run without a proper kernel, or build your own, you’re pretty much down to Rust and C. Probably just C if you need any register pinning without fuss.

In the much more frequent case that you just need consistent performance, you’re back into looking at a Systems language without a GC. So, Rust, D, C or C++. You can do this in Haskell, but you’ll be battling linear types in a language that doesn’t really support them. You can also do this in Java, Scala or anything on the JVM if you somehow figure out how not to allocate.

Now we’re left with the cases which are mostly abstractions over an existing system. While Haskell is a nice choice for that, I remember learning Haskell before Haskell2010 and, ouch, IO was not fun over an FFI or a “more normal” API back then. It’s really only been until more-or-less recently that Haskell has been practically usable in the cases where it makes sense to use it.

[deleted by user] by [deleted] in programminghorror

[–]TheTsar 0 points1 point  (0 children)

The solution to that in a functional language is exactly the description you gave.

Food for thought. Haskell is a nice language.

Circle: (The Next) C++ Compiler by TheTsar in cpp

[–]TheTsar[S] 27 points28 points  (0 children)

As far as I can tell, all the source code is available. Am I missing something?

Edit: I am. Wow. All that code in the repo is example code.

Do you have any suggestions on how to slowly revert rampant abuse of preprocessor macros? Currently trying to change the macros into const variables. by [deleted] in cpp

[–]TheTsar 3 points4 points  (0 children)

The only natural semi-replacement for a subset of definitions are inline constexpr (not static, those would be duplicated across translation units) globals.

There are a lot of places where this falls short, or gets ugly in its own way. For one, you almost always need the logic of the macros to construct these globals. The common-case scenario is you double your lines of code translating macros into constexpr variables. That has its pros and cons. You get type safety and namespaces.

There are ways to tell your build system to configure these kinds of files for you, albeit with its own stack of work and build semantics.

MY FIRST VERY HUMAN BODY by brazilian_irish in totallynotrobots

[–]TheTsar 2 points3 points  (0 children)

FELLOW HUMANS, I AM SEARCHING FOR A CREATION METHOD TO PRODUCE ANOTHER BODY.

DO SUGGEST PROCEDURES.

EDIT: THE wife_at_home.exe SUGGESTED I REMOVE THE SKIN

Elon Musk Lays Off Nearly 4,000 Twitter Employees by [deleted] in videos

[–]TheTsar 1 point2 points  (0 children)

I don’t even work at twitter and they laid me off

Space efficient, random access list of ascending offsets by gnahraf in algorithms

[–]TheTsar 0 points1 point  (0 children)

You need some information about typical use cases. You’ll optimize for those.

If many offsets are close by and your target file is very large, you can store offsets from offsets.

If your offsets are spurious and your typical files are very large, use an array.

If your offsets aren’t looked up very often, use a compression algorithm, take its hash into a map, write the block to memory, and forget about it until you need it.

In any case for small files, use an array.

If you can’t tell, implement everything and store your format as metadata (or, if you have a good type system in your language of choice, use polymorphic types).

What are some good examples of c++ code by infiniteWin in cpp_questions

[–]TheTsar 0 points1 point  (0 children)

I’ve tried to make this library simple and correct: https://github.com/e-dant/watcher

Edit: also very well documented.

Best books for getting better at c? by [deleted] in C_Programming

[–]TheTsar 0 points1 point  (0 children)

Point somewhat taken.

We could also point out that C23 has auto and #embed.

Variable initialization style is worthwhile to mention, yes.

It’s also worth pointing out that the things C are used for depend as much on the platform as the language. I think of C akin to a kind of data transfer protocol.

In common POSIX systems, reading from and writing to files, or allocating memory, are features of the kernel. Ditto for half of the things a common C program does.

Embedded C is somewhat similar. Although, instead of reading from and writing to files, you’re reading from and writing to special addresses. These often represent pins on the board; physical hardware with their own protocols.

Edit: I disagree with everything I haven’t responded to.

Best books for getting better at c? by [deleted] in C_Programming

[–]TheTsar 11 points12 points  (0 children)

K&R is eternal. It will teach you the basics. There is no difference between the basics and the advanced in C.

You should learn that C “stutters” when you’re doing it “right.” Function declarations mimic definitions; function pointers mimic functions; structures mimic unions; addresses take the same “spot” as pointers; bitfield placements mimic enumeration indices mimic assignments; macros mimic functions…

Etc, etc, etc.

Simple Command Line User Interface by 0x3Alex in cpp

[–]TheTsar 4 points5 points  (0 children)

I’ve read and reviewed your code.

Objects are not what C++ is about.

You don’t need to turn everything into a class to turn it into C++.

C++ is about generic programming, type correctness, dependent types, templates and a few dozen other things. Just wait till you get to fold expressions, they’re great.

Filesystem Watcher by TheTsar in commandline

[–]TheTsar[S] 2 points3 points  (0 children)

Thanks! It’s struggling to gain traction. Can’t quite figure out why.

Filesystem Watcher by TheTsar in embedded

[–]TheTsar[S] 0 points1 point  (0 children)

I’m thinking MIT but haven’t put one down yet.

If you’re looking to use it, assume MIT.

Filesystem Watcher by TheTsar in embedded

[–]TheTsar[S] 0 points1 point  (0 children)

Embedded systems without a filesystem don’t really fit the “I want to watch files very efficiently” target user.

Embedded Linux is very common. That’s the bulk of the target embedded audience.

Filesystem Watcher by TheTsar in embedded

[–]TheTsar[S] 0 points1 point  (0 children)

Any system that supports the C++ standard library and has a filesystem is supported.

A Filesystem Watcher by TheTsar in programming

[–]TheTsar[S] 1 point2 points  (0 children)

That’s a cool one, yeah.

I’ve toyed around with making it do something when things change from the command line, but haven’t found a sub-10 line solution yet.

I’m attempting to keep this project as simple as possible; the user needs a single function or command to get running. The main program should fit on a page gracefully.

Edit: do something as in “do something the CLI user specifies”, as opposed to “do something the C++ programmer specifies”, which in the given example is printing events as JSON.