326
10

Delimited flat-file parsing often leads to brittle index-based code. In this post, I show how enums make field positions easier to read and maintain.

In the examples below, we assume the input has already been split:

String[] split = delimitedData.split("\\|");

There are caveats of using the split method this way, but they are outside the scope of this post.

Direct indexing

DbData existingData = dbHandler.getExistingData(
    split[2],
    split[7],
    split[8],
    split[9]
);

Direct indexing is compact, but brittle and hard to scan.

Local variables

String id = split[2];
String date = split[7];
String time = split[8];
String reason = split[9];

DbData existingData = dbHandler.getExistingData(
    id, 
    date, 
    time, 
    reason
);

Local variables improves readability at the call site, but field mappings are still scattered across the code base.

Enum mapping

public enum FlatFileField {
    ID(2),
    DATE(7),
    TIME(8),
    REASON(9);

    private final int index;

    FlatFileField(int index) {
        this.index = index;
    }

    public int index() {
        return index;
    }
}

DbData existingData = dbHandler.getExistingData(
    split[FlatFileField.ID.index()],
    split[FlatFileField.DATE.index()],
    split[FlatFileField.TIME.index()],
    split[FlatFileField.REASON.index()]
);

Comparison

Approach         Pros                                         Cons                                                        
Direct indexing Concise                                     Uses magic numbers, hard to maintain, higher cognitive load
Local variables Readable at call site                       Field mapping still scattered                              
Enum mapping     Centralized field positions, clearer intent Require an additional enum                                  

Takeaway

Enums are a simple way to replace magic numbers with meaningful names when working with delimited data. They improve readability and centralize field positions. When parsing logic grows beyond simple positional access, a dedicated parser or DTO is usually a better choice.

327
65
Doing nothing at work (www.seangoedecke.com)

Many engineers should be doing less work. I don’t necessarily mean producing less code or fewer changes, but literally working fewer hours in the day. When they do work, they should be working at a slower pace. I like to aim to be running at 80% utilization by default: unless I have a high-pressure project going on, I spend 20% of my workday away from the computer.

328
26
329
21

Using Kubernetes Event Driver Autoscaling to scale worker pods to 0 based on reading queues or checking APIs. Implemented for Pixelfed, Bookwyrm, and gitea action runners, with the runners scaling up to 4 pods, with examples.

330
2

Given how quickly things evolve, it's easy to get lost in the numerous offerings and hard to get the best deal. So, what do you use? Both clients/harnesses and LLM providers or local setups would be interesting.

Personally, I've been using opencode with Github copilot for work. I'm currently looking for cost-effective provider for personal work. Maybe openrouter with one of the cheap models?

331
11
332
13
submitted 2 months ago* (last edited 2 months ago) by HaraldvonBlauzahn@feddit.org to c/programming@programming.dev

The text is a bit abstract. Disallowing mutation of values can have a lot of practical advantages, not unlike disallowing global variables. For example, strings and tuples are immutable objects in Python, and this makes it possible that they can be used in dictionaries as keys.

Here is an tutorial/example which shows how changing physical entities can be modeled in this way, with the example of describing a rocket: https://aphyr.com/posts/312-clojure-from-the-ground-up-modeling .

This has a lot in common with how things are described in physics, for example.

333
10
submitted 2 months ago* (last edited 2 months ago) by HaraldvonBlauzahn@feddit.org to c/programming@programming.dev

I posted this because I think it is really cool: Clojure is a great and extremely elegant language, which has a powerful approach to concurrency: Data is immutable by default, like Python's strings and tuples. (Here more about this idea.)

Because this Clojure dialect runs in the Python bytecode interpreter, it has via its interop features access to all of Python's libraries.

And there is one more advantage, which is less obvious: Python can be extended with native extension modules via a C API. And this does not only allows code written in C and C++ to be called (via boost::python and pybind11), but also code written in Rust - because Rust supports calls via the C ABI, and this can be used in comfortable Python wrappers like PyO3, in the same way as C++ with pybind11. And the concrete advantage of Rust here is that it is a far better match to Clojure's immutability-by-default, and its safe concurrency support.

334
45
335
17

cross-posted from: https://infosec.pub/post/47574072

Hello lemmings, I made a program to ping every IPv4 address and collect data on respondents. I am almost done, but I want feedback on things I should change or how I can improve my current record of 5,000 pings / second.

I am currently aware that I need to properly parse the data I receive on the receive socket, since it's possible the TTL router messages might be confused as replies. ICMP is used on networks to inform other machines of network problems.

One issue I'm aware of is the tuning that has to go into maximizing throughput while also avoiding a total system freeze. My code seems to spend too much time opening sockets that it leaves no room for the actual OS. My only fix currently is limiting the CPU time to the ping timeout I used.

The overall program works like this: It keeps a linked list / pool of task objects. All objects are initially in the "free list" and then when they become associated with a socket, they move to the "active list". The program first checks for updated sockets with epoll which results in like 5% of sockets giving a response. It then closes any tasks that have timed out via linked list in O(1) each. The slow part is when it creates new sockets, since it doesn't really know when to stop, besides when the non-blocking socket informs it that it would block. I implemented a time limit on sending that is currently the maximum of the ping timeout. To increase throughput it seems like I need to streamline how I send ICMP packets.

https://github.com/bneils/PingStorm

336
11
submitted 2 months ago* (last edited 2 months ago) by AstroLightz@lemmy.world to c/programming@programming.dev

Let's says you want to make a program that takes user input and follows the CRUD structure for some data. This program would be executed from the terminal and wouldn't be used in any other projects.

If this program was made in a language that supports creating packages for other programs (e.g. Python, Rust, NodeJS), should this program be a 'package', or should it be a standalone program that has a simple "setup" script?

Assume this is a CLI/TUI app that runs in a Linux terminal.

EDIT: I'll provide some more details since it seems I was too vague:

This program would allow the user to create 'Script' objects that would be saved to a file on their system. These objects would contain metadata such as a name, the command to run, and a description.

These Script objects would only be used by this program, and by the user. (i.e not a system program)

337
17
338
20
339
101

I have been thinking of learning some programming recently, but I don't feel confident enough. Is there any point in beginning with something like Zig or Go, and switching to something more serious later?

340
28
341
17
342
6
submitted 2 months ago* (last edited 2 months ago) by Ghoelian@piefed.social to c/programming@programming.dev

nesbot/carbon is a popular date time library for php, included by default in Laravel, for example. It has amassed almost 700 million downloads on packagist.org.

Yesterday, I was looking through the repository, looking for documentation, when I noticed the sponsor section of their readme.

Almost all of the companies listed are betting/gambling sites, some of them specifically made to circumvent for example GamStop, Britain's system where gamblers can block themselves from gambling. One of the sponsor's images links to a TrustPilot profile that has been removed for breaking their guidelines.
Until just now I had not even noticed the "show more" button. I found at least another one with a deleted TrustPilot profile. There's so many more.

I raised an issue about this on their repository, but it just got deleted, not closed.

What the hell is going on here? Why are all these shady companies sponsoring this project? Is the one circumventing GamStop even legal?

image

343
-27

Dave explains the magic of fopen and the multiple ways it can be used that many programmers do not even know about.

344
11
345
17
Gaussian Point Splatting (momentsingraphics.de)
346
16

This is a general collection of my last week with the AI and development. All the comments and feedback are welcome. And the question remains, what I'm not seeing it?

347
9
348
107

In case you hit some technical obstacle, here is an archived version:

https://web.archive.org/web/20260602195828/https://www.404media.co/microsoft-wants-to-make-people-addicted-to-scout-its-new-ai-assistant-internal-documents-reveal/

Key citation (emphasis mine):

Overview and Plan with Project Lobster,” seen by 404 Media has a subheading called “ClawPilot Overall Plan,” which notes “three phases” to its launch plan. The first phase is “Make people addicted.”

“Continue shipping the standalone ClawPilot experience. Pilot the UX, grow the user base, and build the skill and tool ecosystem that makes people depend on it daily. This is already happening organically,” the document says. Omar Shahine, the Microsoft executive leading the project, adds that in its pilot with Microsoft employees, they have seen “Daily Usage with High Retention and intensity of usage (chats, queries, workflows, skills).” The additional phases of the plan involve connecting ClawPilot to other AI tools and eventually adding new features.

349
28
submitted 2 months ago* (last edited 2 months ago) by remustan37@sh.itjust.works to c/programming@programming.dev

As the title says, which programming language would you agree had the best libraries for visualisation (graphs, 3d models, charts, networks, animations, etc)?

Prefer languages with libraries that have more visulatizaton features than say, ease of using the libraries.

350
56
What we lose when we stop coding (newsletter.humanwhocodes.com)
view more: ‹ prev next ›

Programming

28304 readers
403 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 3 years ago
MODERATORS