HNHacker News
TopNewBestAskShowJobs

palotasb

458 karma · joined July 31, 2009

boldizsar.palotas at gmail.com

https://github.com/palotasb

submissionscomments
palotasb··on Use TOML for `.env` Files?
I'm an ordinary human and I disagree. I would not expect a blank line to end the [hosts] table. I find it nice that you can visually separate different categories of entries under a table. I also find it nice that global entries must be at the top of the file – more organized and fewer opportunities for such global entries to get lost.
palotasb··on TensorFlow for Python is dying?
https://www.fast.ai/
palotasb··on Egui commit: Implement accessibility APIs via AccessKit
Don't pass the -m argument to git commit. It will open you $EDITOR an you can edit the commit message there.
palotasb··on Affinity 2
To be fair, this was using Darktable 3.6 (I had to open /Applications/darktable.app/Contents/info.plist to check as there is no About menu). Updating to the current latest 4.0.1.1_arm64 at least the metadata popup issue is mostly, but not 100%, fixed, and I could navigate through my catalog.

Adding: Even though my Fujifilm X-T4 is listed as supported on https://www.darktable.org/resources/camera-support/, and the preview images in grid mode appear, opening a single image displays two visually overlapping error messages about not being able to open the raw file. (One message is about switching to lighttable, the other about not being able to read white balance info. The image is not displayed.)

palotasb··on Affinity 2
I'll substantiate regarding UI: On a Mac it has no items in the menu bar. The default cursor is changed to a low-resolution raster image instead of the default OS cursor. The image metadata pop-ups keep appearing even though darktable is in the background and I'm typing in a textbox in my browser. Something's really off with the UI toolkit they rely on.

I agree with the GP that the UI makes it practically unusable. Prehistoric, and I'd be surprised if this can be used by anyone as-is. I'd take a look at the features, but while it's importing my catalog I can't open any subfolders to look at images already imported. Once I click open my top-level Pictures folder, it closes it again after half a second.

palotasb··on The case for JPEG XL
Is there a "latest draft" standard available legally and for free for wider audiences? C++, also ISO standardized, does this and I believe it has contributed greatly to its adoption and post-C++11 renaissance. See https://en.cppreference.com/w/cpp/links#C.2B.2B_Language_and... . For now, JPEG XL might as well be a proprietary closed format for most hackers here.
palotasb··on Show HN: I made an offline-ready hiking trail companion app
For mapping out the hard parts, there's a separate "plugin" that you can enable to turn on contour lines and hill shading or slope map an overlay on the main map https://osmand.net/docs/user/plugins/contour-lines
palotasb··on Show HN: I made an offline-ready hiking trail companion app
I would also recommend checking out OsmAnd Maps in this space. I use it both for hiking and cycling. I love the UI customizability, for example being able to overlay a satellite map on top of a trail map and having a slider to adjust opacity – this really helps with orientation. On the cycling front it is the only app I know that has a sensible route planner and turn-by-turn navigation. It's open source too, and based on OSM data: https://github.com/osmandapp/ (No affiliation, just started using it after Gaia GPS lost my data.)
palotasb··on Please do not use Python for tooling
I'm not sure about the problem of brittleness caused by buggy scripts you must rely on -- you'd get that in any language. But if the brittleness is caused by slightly different dependencies being installed for each developer or CI machine, I also recommend creating development environment setup and activation scripts that create a reproducible development environment (based on a requirements.txt generated via pip freeze, committed into the repo; or similar).

Even if the platforms you depend on don't do this, you can do it yourself. It won't fix their bugs, but it will make the development environment more deterministic.

I agree that not all embedded developers should have to work with daily or even monthly. Ideally, all they have to do is run to commands:

    ./scripts/setup-dev-env
    source ./scripts/activate-dev-env
However, embedded software development heavily relies on invoking build systems, compilers, analyzers and other tools -- calling project-specific programs and scripts. At least one person on each project should be familiar with setting these up for the 1st time, document their usage, and support others.
palotasb··on Please do not use Python for tooling
> If you use a language that can produce binaries the job of ensuring you have all the dependencies in all the right versions is a one-time job: it happens at build time.

This is not true for most language toolchains by default as far as I know. Most languages don't produce fully self-contained binaries. The developer have to do extra work to create self-contained binaries, otherwise the users still have to work to get the dependencies necessary.

What makes tooling different from system software in my view is that you're using software on a per-project basis, updating it as the project evolves. The developer of the tooling and the user of the tool (another developer) both have responsibilities. They have to agree on a common platform that the tools can target. The tool author is responsible for documenting explicitly any prerequisites and setup steps and they must make sure the tool doesn't implicitly depend on anything more. The user must make sure they've set up an environment for the project that meets the tools needs.

I've personally found that Python works reasonably well for tooling if I as a tool author follow a few guidelines. I require the users only to have a shell, python3, and python3-venv or miniconda installed on their base system. I provide a setup/activation script that creates/activates a virtualenv or a Conda env in the project directory and makes sure that the packages in the also-included requirements.txt or environment.yaml are installed before the tooling is run.

Since the scripts are provided as part of the tools, the tool author becomes responsible for automating the creation of a working environment for the user of the tool. This process can be automated and reproducible based on a frozen requirements.txt or similar, so most of the brittleness can be eliminated by the tool author.

I don't think any other tool implementation language would provide huge benefits to the users. They would usually still need to install some system-wide prerequisites and use some kind of per-project activation script.

The reason I like Python as a tool author is because it's better than writing shell scripts, and it's still easy to include as source with any kind of project. The standard library -- with the argparse, subprocess, urllib, shutil, etc. modules -- is good enough that for simpler tools no external dependencies (nor any activation script nor requirements.txt) are needed, but familiar for many developers.

palotasb··on I can’t believe that I can prove that it can sort
No, it's not. Previously discussed on HN here: https://news.ycombinator.com/item?id=28758106 (https://arxiv.org/abs/2110.01111)
palotasb··on The Grug Brained Developer
> grug not like big complex front end libraries everyone use

> grug make htmx and hyperscript to avoid

https://twitter.com/htmx_org/status/1539713592794169346

https://github.com/bigskysoftware

palotasb··on Things I can’t do on macOS which I can do on Ubuntu (2020)
> Window snapping

Not built-in, but the open source https://rectangleapp.com/ supports window snapping by mouse and via shortcuts.

palotasb··on ISO C became unusable for operating systems development
Undefined behavior entails "there are no restrictions on the behavior of the program", meaning anything can happen, including executing the opposite of the program text. Implementation defined behavior is saner in the sense that program behavior is still defined. Examples of the latter are the exact type of std::size_t or the number of bits in a byte: https://en.cppreference.com/w/cpp/language/ub
palotasb··on Using Zig's translate-C to understand weird C code
Any time the spiral rule comes up, I like to point out that it's wrong. It is instructive in a way because one learns more about C declaration syntax, but it is even more instructive to recognize why it is wrong.

The spiral rule works only if there is no pointer to pointer or array of array in the type. But take this for example:

        +----------------------------+
        | +-----------------------+  |
        | | +------------------+  |  |
        | | | +-------------+  |  |  |
        | | | | +--------+  |  |  |  |
        | | | | |  +--+  |  |  |  |  |
        | | | | |  ^  |  |  |  |  |  |
    int * * ¦ ¦ ¦ xxx[1][2][3] |  |  |
     ^  | | | | |     |  |  |  |  |  |
     |  | | | | +-----+  |  |  |  |  |
     |  | | | +----------+  |  |  |  |
     |  | | +---------------+  |  |  |
     |  | ---------------------+  |  |
     |  +-------------------------+  |
     +-------------------------------+
The type of xxx is a [1-element] array of [2-element] array of [3-element] array of pointer to pointer to ints. I drew a spiral that passes through each specifier in the correct order.

Notice that to make the spiral correct it has to skip the pointer specifiers in the first three loops. This is marked by ¦. This is not mentioned in the original spiral rules and one could be forgiven to parse the expression as xxx -> [1] -> pointer -> [2] -> etc. following a spiral that doesn't skip the pointers.

The Right-Left Rule is quoted less frequently on HN but it's a correct algorithm for deciphering C types: http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html

The spiral rule can be modified to process all array specifiers before all pointer specifiers, but then you'd have to specify that the order to do so is right and then left. At that point it's just the Right-Left Rule.

palotasb··on Namedtuple in a Post-Dataclasses World
NamedTuple or namedtuple instances are tuple instances that have the same properties that regular tuples have. They are immutable (you cannot reassign their fields), you can index into them (a[0], a[1] instead of a.x and a.y), you can unpack them with *a. They can have methods like regular classes can, including additional @property methods. A NamedTuple class cannot inherit from another class, not even other named tuples.
palotasb··on Clockwise/Spiral Rule
Any time this comes up I like to point out that the spiral rule is wrong. It is instructive in a way because one learns more about C declaration syntax, but it is even more instructive to recognize why it is wrong.

The spiral rule works only if there is no pointer to pointer or array of array in the type. But take this for example:

        +----------------------------+
        | +-----------------------+  |
        | | +------------------+  |  |
        | | | +-------------+  |  |  |
        | | | | +--------+  |  |  |  |
        | | | | |  +--+  |  |  |  |  |
        | | | | |  ^  |  |  |  |  |  |
    int * * ¦ ¦ ¦ xxx[1][2][3] |  |  |
     ^  | | | | |     |  |  |  |  |  |
     |  | | | | +-----+  |  |  |  |  |
     |  | | | +----------+  |  |  |  |
     |  | | +---------------+  |  |  |
     |  | ---------------------+  |  |
     |  +-------------------------+  |
     +-------------------------------+
The type of xxx is a [1-element] array of [2-element] array of [3-element] array of pointer to pointer to ints. I drew a spiral that passes through each specifier in the correct order.

Notice that to make the spiral correct it has to skip the pointer specifiers in the first three loops. This is marked by ¦. This is not mentioned in the original spiral rules and one could be forgiven to parse the expression as xxx -> [1] -> pointer -> [2] -> etc. following a spiral that doesn't skip the pointers.

The Right-Left Rule is quoted less frequently on HN but it's a correct algorithm for deciphering C types: http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html

The spiral rule can be modified to process all array specifiers before all pointer specifiers, but then you'd have to specify that the order to do so is right and then left. At that point it's just the Right-Left Rule.

palotasb··on Ask HN: Good C++ code bases to read?
I recommend the LLVM source code. I've worked a bit with it implementing toy compilers and using LLVM as a backend for generating x86/SPARC object code. Just compiling it is a nice exercise if you're new to C++ and CMake (as I was, then).

I would start by reading the LLVM Programmer's Manual [prog man] and the LLVM Coding Standards [code stand] and looking up how the code they reference and the examples are implemented and how they interact with each other. You can browse the code in the LLVM Mirror Git repository [llvm-git] or the cross-referenced Doxygen [llvm-doxy] (has very useful links!). If you're willing to spend the time it might be worth setting up the codebase in your IDE of choice with the proper integrations to be able to browse and cross-reference the source code there.

There is a lot to learn especially from the Important and useful LLVM APIs and Picking the Right Data Structure for a Task (and the corresponding code) in the Programmer's Manual. The data structures under llvm/ADT could be especially useful to look at. They are good generic data structures that you may even want to directly reuse in your own project, but they are much easier on the eyes and closer to what you and I would want to see in our own codebases than the source code of the standard library or the Boost data structures.

[prog man]: https://releases.llvm.org/4.0.1/docs/ProgrammersManual.html

[code stand]: https://releases.llvm.org/4.0.1/docs/CodingStandards.html

[llvm-git]: https://github.com/llvm-mirror/llvm

[llvm-doxy]: http://llvm.org/doxygen/modules.html

PS. The Coding Standards will contain a lot of subjective stuff that makes sense inside LLVM for consistency but you don't want to adopt verbatim into an existing (maybe not even a green field) project, like naming variables with Capital letters. You can skim these parts, but it might be useful to know about the existence of these types of issues.

palotasb··on Show HN: Deploy to K8s without YAML using ShuttleOps
I've been experimenting on a personal project with https://www.pulumi.com/ where you can do the configuration and deployment in Python or JavasScript and I think I can recommend it.
palotasb··on All DuckDuckGo bang operators on one page
The page doesn't list my favorite operator,

  !ducky <search term>
that will navigate to first result. It's named after the "I'm Feeling Lucky" button that used to exist on Google. It's useful with Firefox keyword bookmarks to navigate to specific pages quickly.

  Bookmark: Python's PEPs
  Location: https://duckduckgo.com/?q=!ducky+site%3Awww.python.org%2Fdev%2Fpeps+%22pep+%s%22
  Keyword: pep
Type in the browser address bar:

  pep <space> 8 <enter>
Will navigate to: https://www.python.org/dev/peps/pep-0008/
palotasb··on Del.icio.us
For future reference, this is what the page says as of this HN post: http://web.archive.org/web/20200729083406/http://del.icio.us...

> July 15, 2020

> Hi, my name is Maciej Ceglowski, the latest (and hopefully last) owner of del.icio.us.

> The site will be back online soon. If you had data stored on del.icio.us after 2010, you'll be able to export it here.

> [...]

> You can reach me at maciej@ceglowski.com

I also hope the site will be back online.

palotasb··on Unit Testing Is Overrated
Well thought-out article with good points and deductions! I have a few counterpoints and I think the example is not the best way to argue against unit testing as there are better ways to implement the same features and write better unit tests without bloating the code.

Looking at the SolarCalculator class, I would go another way first and refactor it like so:

    public class SolarCalculator
    {
        public static SolarTimes GetSolarTimes(Location location, DateTimeOffset date) { /* ... */ }
    }
1. Made the method static (make it a free function in other languages) 2. Take an explicit Location parameter 3. Return a SolarTimes object directly, not async, not a Task<solarTimes>, and remove Async from the name 4. Drop the now unnecessary class LocationProvider member

This becomes more easily unit testable without any excess Arranges steps at the beginning.

    public class SolarCalculatorTests
    {
        [Fact]
        public Task GetSolarTimes_ForKyiv_ReturnsCorrectSolarTimes()
        {
            // Arrange
            var location = new Location(50.45, 30.52);
            var date = new DateTimeOffset(2019, 11, 04, 00, 00, 00, TimeSpan.FromHours(+2));

            var expectedSolarTimes = new SolarTimes(
                new TimeSpan(06, 55, 00),
                new TimeSpan(16, 29, 00)
            );

            // Act
            var solarTimes = solarCalculator.GetSolarTimes(location, date);

            // Assert
            solarTimes.Should().BeEquivalentTo(expectedSolarTimes);
        }
    }
The GetSolarTimes function is now purely computational and has no plumbing at all (stealing terms from chimprich). I think the original author would also agree that unit testing SolarTimes GetSolarTimes(Location location, DateTimeOffset date) has none of the problems that unit testing async Task<SolarTimes> GetSolarTimesAsync(DateTimeOffset date) had.

(Added benefit: the interface is more flexible, it can be reused in more use cases without modification but that is not the point.)

I find that such a refactoring often solves all of the problem entirely. It might seem like we just swapped the problem under the rug and forced the calling code to add the complexity (and the tests, interfaces, mocks etc.) that we discarded, but in practice this is often not the case.

    // Uses original async implicit-location interface
    // (assumes an existing solarCalculator instance)
    var solarTimes = await solarCalculator.GetSolarTimesAsync(date);

    // Uses proposed non-async explicit-location interface
    // (assumes an existing locationProvider instance)
    var solarTimes = SolarCalculator.GetSolarTimes(await locationProvider.GetLocationAsync(), date);
The reason we can often get away with this in practice is that the complexity increase in the caller is small. We did not add additional state to the caller, we did not push more testing/mocking complexity to the caller. The assumed locationProvider instance in the caller replaces the solarCalculator instance in the caller. If testing/mocking locationProvider is required, testing/mocking solarCalculator ought to have been tested too. We require the caller to test/mock something else, not something new.

If the original async Task<SolarTimes> GetSolarTimesAsync(DateTimeOffset date) interface is required nonetheless, it can be implemented as a pure "plumbing" function. As such I would agree that unit testing it would provide less value than integration testing. A simple pattern that can be applied here instead of an ILocationProvider interface and all the baggage that comes with it is using a Func<Task<Location>> or lambda instead. This allows both testing the instance with custom location providers and unhindered usage of the SolarCalculator class without always needing to inject a dependency.

    public class SolarCalculator
    {
        private readonly Func<Task<Location>> _locationProvider;

        // default constructor for normal usage
        public SolarCalculator() {
            internalReaLLocationProvider = LocationProvider();
            _locationProvider = async () => internalReaLLocationProvider.GetLocationAsync();
        }

        // constructor for custom locations and testing
        public SolarCalculator(Func<Task<Location>> locationProvider) {
            _locationProvider = locationProvider;
        }

        // Gets solar times for current location and specified date
        public async Task<SolarTimes> GetSolarTimesAsync(DateTimeOffset date) { 
            return GetSolarTimes(_locationProvider(), date);
        }
        
        public static SolarTimes GetSolarTimes(Location location, DateTimeOffset date) { /* ... */ }
    }
(Sorry, I haven't implemented the IDisposable pattern for internalReaLLocationProvider and I might have misplaced an async keyword or two because C# is not my most recent language.)

To support the "pyramid-driven" paradigm I argue that the most complicated part of this feature is the solar time calculation and it would well deserve a large test suite containing many test cases like GetSolarTimes_ForKyiv_ReturnsCorrectSolarTimes above (edge cases, diverse locations, etc.). Conversely, the higher-level functions don't need this level of testing. Since they contain no complex logic, I usually assume that if they work for one input, they will work for any other. Testing the async, automatic-location version with the simple Kyiv-based input is enough, there is no need to test it with midnight sun and all the same edge cases as the base function.

The point I'm making is that unit testing is not as overrated as the original example suggests. The code can be modularized better (not by making everything an interface), with a well-unit-testable "computational" part and a part which is mostly "plumbing". I agree with those saying that the second part benefits more from integration testing than unit testing, and I can agree with keeping them "as highly integrated as possible, while keeping their speed and complexity reasonable". But I insist that unit testing the 1st part and writing it in a way that it is unit testable is important.

palotasb··on State Machines in Rust
https://github.com/p-org/P/wiki/PingPong-program for anyone else wondering
palotasb··on Zig cc: A drop-in replacement for GCC/Clang
The spiral rule works if "pointer to" and "function returning"/"array of" alternate but it breaks if they don't, i.e., if you have arrays of arrays or pointers to pointers.

    int** arr1_of_arr2_of_arr3_of_ptr_to_ptr_to_int[1][2][3]
In this case, spiraling between [1], ×, [2], ×, [3], int is obviously wrong, the correct reading order is [1], [2], [3], ×, ×, int. (Edit: read × = *)

The Right-Left Rule is quoted less frequently on HN but it's a correct algorithm for deciphering C types: http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html

palotasb··on SQLite Is Serverless
You can use the memvfs module to load in-memory databases if you're using the C API. I'm not sure how many higher-level APIs support it though.

[1] https://stackoverflow.com/a/53453338/3063 [2] https://www.sqlite.org/loadext.html#example_extensions [3] https://www.sqlite.org/src/file/ext/misc/memvfs.c

palotasb··on Counting Bugs in Windows Calculator
This seems like a stolen article. The URL should be changed to the original blog post: https://www.viva64.com/en/b/0615/
palotasb··on Implications of Rewriting a Browser Component in Rust
In Rust, or any statically typed language such as C++ or Java, the idiomatic way to handle untrusted input is to treat it as a "bag of bytes" before you access it. Then either parse it into a strongly typed object or bail out of parsing. The strongly typed object is safe to use. Bailing out (throwing an exception or returning an error type) does not allow the program to continue assuming that the (malformed) input was correct.
palotasb··on Dotfile madness
That's why I never use $HOME for personal files. All of my files are in the Dropbox folder or another custom folder on my work PC. It's nonstandard, so no one litters in it besides me.
palotasb··on Glitter bomb tricks parcel thieves
You're assuming that if it's fake, the spray is still real.
palotasb··on Pointers in C (2010)
Forget the spiral rule. That's putting an if-statement into a buggy algorithm instead of using the correct algorithm.

The simplest correct algorithm is to 1. From the identifier, go right one by one in the current parenthesis level and process every element. 2. From the identifier again, go left one by one in the current parenthesis level and process every element. 3. Repeat from step 1. except the "identifier" is the part you already processed.

Within step 1, you will encounter arrays and function parameter lists. Within step 2, you will encounter pointers (in C++ also references), const and volatile modifiers, and named types. Neither algorithm covers it, but if there is no identifier to start with, then you start at the most nested level between the elements that may occur in step 1 and 2 and if you find a comma, you were just processing the type of a function parameter.

Spiraling is unnecessary. Within step 1, you DON'T spiral because of arrays of arrays or you turn back because of a closing parenthesis so a spiral doesn't need to guide you. Within step 2, the elements on the right are all processed already, so a spiral going back right will hit nothing. For simple but common cases like "const int * ptr * const_ptr_to_const_int" you're spiraling around nothing on the right-hand side.

Let's rework and simplify the examples from the http://c-faq.com/decl/spiral.anderson.html page. Comments show what the result of parsing an element is. Process >> >> left to right and << << right to left.

         char * str [10];
    //          XXX >>>> "str is", "an array of 10..."
    //   <<<< < XXX      "pointer to", "char"
    
         char * ( * fp ) ( int, float * );
    //              XX                    "fp is"
    //            < XX                    "a pointer to"
    //          XXXXXXXX >>>>>>>>>>>>>>>> "a function taking (int, float*) and returning"
    //   <<<< < XXXXXXXX                  "a pointer to", "char"
    
         void (* signal (int, void (* fp) (int))) (int);
    //                              < XX                "fp is", "a pointer to"
    //                             XXXXXX >>>>>         "a function taking (int) and returning"
    //                        <<<< XXXXXX               "void", "and it is a function parameter to something else"
    //           XXXXXX >>>>>>>>>>>>>>>>>>>>>>>>        "signal is", "a function taking (int, void(*fp)(int)) and returning"
    //         < XXXXXX                                 "a pointer to"
    //        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX >>>>> "a function taking (int) and returning"
    //   <<<< XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       "void"
    
         const char * chptr;
    //   <<<<< <<<< < XXXXX "chptr is", "a pointer to", "char", "that is const"
    // Notice how a spiral would make this worse and the page omits drawing it for a reason
    
         char * const chptr;
    //   <<<< < <<<<< XXXXX "chptr is", "a constant", "pointer to", "char"

         volatile char * const chptr;
    //   <<<<<<<< <<<< < <<<<< XXXXX "chptr is", "a constant", "pointer to", "char", "that is volatile"
Notice that in the examples where Anderson drew any spirals, it only made sense because there was a single "<<"/">>" element to the left and to the right of the XXXX part. In all other cases, spirals don't make sense because you might have to avoid the element on the left or there is no element on the right to spiral through, you're just going right-to-left. Why fit a spiral when a straight-line arrow will do?
← PreviousPage 2 of 3Next →