Programming

22006 readers
116 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 2 years ago
MODERATORS
126
127
128
 
 

About enshitification of web dev.

129
 
 

Perhaps the most powerful and widely used tool for literate programming ist Emacs org-mode with the babel extension. I have used it, and it is good!

However, org-mode puts a hurdle to novice users - to practice literate programming, they need to learn a bit of Emacs, which is a task in itself.

I linked the above project because it has two interesting properties:

  • One can write the literate document in Markdown. This is not as powerful as org-mode, which is tailored to larger documents, but very accessible.

  • One can modify the generated source files directly, and they are automatically read back into the literate document. This makes it much easier to work with existing tools that modify source code.

130
 
 

I had an interesting email come in about billing. GitHub thinks I owe them money...cents on the dollar but still $$. I am on the free tier on GitHub and have been the past 15+ years. image
Up til recently, ive had no bills and im not an admin on any org. It looks like all my GitHub actions on my repos are accruing billing now. None of these repos are private. So im not 100% why this is occurring.

Has this happened to anyone else? Is there something im missing here?

131
 
 

Summary by Dan Luu on the question about whether for statically typed languages, objective advantages (like having measurably fewer bugs, or solving problems in measurably less time) can be shown.

If I think about this, authors of statically typed languages in general at their beginning might not even have claimed that they have such advantages. Originally, the objective advantage was that for computers like a PDP11 - which had initially only 4 K of memory and a 16-bit adress space - was that something like C or Pascal compilers could run on them at all, and even later C programs were much faster than Lisp programs of that time. At that time, it was also considered an attribute of the programming language whether code was compiled to machine instructions or interpreted.

Todays, with JIT compilation like in Java and the best implementation of Common Lisp like SBCL being at a stone's throw of the performance of Java programs, this distinction is not so much relevant any more.

Further, opinions might have been biased by comparing C to memory-safe languages, in other words, when there were perceived actual productivity gains, the causes might have been confused.

The thing which seems more or less firm ground is that the less lines of code you need to write to cover a requirement, the fewer bugs it will have. So more concise/expressive languages do have an advantage.

There are people which have looked at all the program samples in the above linked benchmark game and have compared run-time performamce and size of the source code. This leads to interesting and sometimes really unintuitive insights - there are in fact large differences between code sizes for the same task between programming languages, and a couple of different languages like Scala, JavaScript, Racket(PLT Scheme) and Lua come out quite well for the ratio of size and performance.

But given all this, how can one assess productivity, or the time to get from definition of a task to a working program, at all?

And the same kind of questions arise for testing. Most people would agree nowadays that automated tests are worth their effort, that they improve quality / shorten the time to get something working / lead to fewer bugs. (A modern version of the Joel Test might have automated testing included, but, spoiler: >!Joel's list does not contain it.!<)

Testing in small units also interacts positively with a "pure", side-effect-free, or 'functional' programming style... with the caveat perhaps that this style might push complex I/O functions of a program to its periphery.

It feels more solid to have a complex program covered by tests, yes, but how can this be confirmed in an objective way? And if it can, for which kind of software is this valid? Are the same methodologies adequate for web programming as for industrial embedded devices or a text editor?

132
 
 

I desperately need some Python help. In short, i want to use multiple keys at once for sorting a dictionary. I have a list of keys and don't know how to convert it to the required list.

This is a single key. The self.items is a list of dictionaries, where d[key] is resolved to the actual key name such as "core_name", that the list is then sorted as. This works as expected for single sort, but not for multiple.

key = "core_name"
self.items = sorted(self.items, key=lambda d: d[key])
key = "label"
self.items = sorted(self.items, key=lambda d: d[key])

Problem is, sorting it multiple times gives me wrong results. The keys need to be called in one go. I can do that manually like this:

self.items = sorted(self.items, key=lambda d: (d["core_name"], d["label"]))

But need it programmatically to assign a list of keys. The following does not work (obviously). I don't know how to convert this into the required form:

# Not working!
keys = ["core_name", "label"]
self.items = sorted(self.items, key=lambda d: d[keys])

I somehow need something like a map function I guess? Something that d[keys] is replaced by "convert each key in keys into a list of d[key]". This is needed inside the lambda, because the key/value pair is dynamically read from self.items.

Is it understandable what I try to do? Has anyone an idea?


Edit: Solution by Fred: https://beehaw.org/post/20656674/4826725

Just use comprehension and create a tuple in place: sorted(items, key=lambda d: tuple(d[k] for k in keys))

133
 
 

I'm very excited to announce that I have recently joined Turso as a software engineer. For many in the field, including myself, getting to work on databases and solve unique challenges with such a talented team would be a dream job, but it is that much more special to me because of my unusual and unlikely circumstances. As difficult as it might be to believe, I am currently incarcerated and I landed this job from my cell in state prison. If you don’t know me, let me tell you more about how I got here.

134
 
 

Biome is a formatter and linter for web languages: JavaScript, TypeScript, CSS, HTML, JSON, and GraphQL.

Version 2 adds type-aware lint rules and it is the first TypeScript linter that does not require tsc. Other new features include:

  • Monorepo support
  • GritQL Plugins
  • Revamped, configurable import sorting
  • Linter domains
  • Bulk suppressions
  • Analyzer assists
  • Many new lint rules
135
21
Project Gemini FAQ (geminiprotocol.net)
submitted 1 month ago* (last edited 1 month ago) by HaraldvonBlauzahn@feddit.org to c/programming@programming.dev
 
 

cross-posted from: https://feddit.org/post/14262415

On the question what are use cases for a Gemini server:

Gemini is kinda a modernized version to the old Gopher protocol. Its purpose is to share hyper-linked text documents and files over a network - in the simplest way possible. It uses a simple markup language to create text documents with links, headings etc.

Here is a FAQ

Main differences with similar technologies are:

  • It is much, much easier to write hyper-linked documents than in HTML

  • a server is much much smaller and easier to set up than a web server serving HTML. It can easily and securely run on a small Raspberry Pi without special knowledge on server security.

  • in difference to gopher, it supports modern things like MIME and Unicode

  • There are clients for every platform including Android and iOS

  • also, there are Web gateways which allow to view stuff in a normal web browser

  • unlike Wikis, it is only concerned about distributing content, not modifying files. This means that the way to store and modify content can be matched to the use case: Write access to content can be via an NFS or Samba server, or via an SFTP client like WinSCP or Emacs.

  • Unlike HTML2, it does not support advertising, tracking, spying to users, and so on.

  • the above two points mean that it does not need user authentication

  • the protocol is text-centric and allows for distraction-free reading, which makes it ideal for self-hosted blogs, small projects or associations, or microblogs.

Practically, for example, I use it to share vacation photos with family.

Two more use cases that come first to my mind:

  • When I did my masters thesis, our lab with about 40 people had a HTTP page hosted on a file server that listed tools, data resources, software, and contact persons. That would be easier to do with Gemini because the markup is simpler. Also, today it would not be feasible to give every student write access to a Apache web server's content because of the complexity of web servers, and the resulting security implications.

  • One time at work, we had a situation with a file server with many dozens of folders, and hundreds of documents. And because all the stuff had been growing kinda organically over many years, specific information was hard to find. A gemini server would have made it easy to organize and browse the content as collaboratively edited hypertext which serves as an index.

136
 
 

cross-posted from: https://lemmy.ml/post/31328788

137
 
 

This is like a clean, simple reincarnation of make. And it is fascinating how it works:

Make is essentially a configuration file which textually describes a directed graph (DAG) of dependencies by their path names, together with embedded shell command lines which build each dependency.

This works more or less well, but if some dependency is missing, one has to add "make clean" commands. Or maybe, just to be sure, "make clean" (which would not be necessary if the tool really unambigously defined the build). Or for example if a system library has changed. Or if an optional dependency appears which was not there before.

And it becomes more complex if build steps run in parallel. Therefore, things like "make config" and so on are needed.

D.J. Bernstein examined these ill-defined cases, and came up with an alternative system, which he called "redo".

Redo turns this inside-out: It uses real shell scripts for building stuff, together with special shell commands that define dependencies. And these commands have dependencies as input, they can for example use what the compiler tells them. (The background is that e.g. in a complex C project with lots of #defines, only the C compiler has a precise picture what it needs). The top-level command runs all these build scripts in the right order. (In fact, they could also be written in Lisp, Java or Guile or whatever, as long as they support the common dependency-defining commands.)

The resulting system is surprisingly simple.

One quality for example is that in a source tree, definitions can be build recursively without any special provisions. No top-level Makefile required.

138
 
 

I don't have much to say, only that I expected flutter to be a bloated fragile abstraction on top of different native GUI APIs, but no.

It's quite fast, relatively easy to develop and it just works.

I'm working on a desktop app that needs a high-perf rust impl, and (for now) flutter looks like a much better choice than tauri.

139
140
141
12
The Leo Text Editor's Home Page (leo-editor.github.io)
submitted 1 month ago* (last edited 1 month ago) by HaraldvonBlauzahn@feddit.org to c/programming@programming.dev
 
 

This is a very interesting but not well-known editor.

Some unusual features it has:

  • it is centered around outlines, this means one can divide a larger source code document into several or many smaller parts
  • it supports generation of output files from such outlines - and can read them back
  • it supports literate programming in a very nice way, and is a bit easier to use than org-mode
  • a section of an outline can appear more than one time in the directed graph of text segments - much like a hard-linked file can appear more than once in a directory tree. For example, one can use this to keep the same text in the on-line help of a CLI program, and in a long-form help document.

Personally, I have used it extensively to generate documentation for a large commercial library around signal processing. The fact that it supports an interlinked "DAG" of text elements made it easy to cross-reference and link important stuff. For exanple, I could maintain a glossary with footnotes, and I could also export it to a braindead ancient source control system called VisualSourceSafe - let a proofreader make changes, and then import it back in, keeping the structure, and merge the corrections via git.

Overall, it can do similar stuff like Emacs + Org-Mode, but while org-modes has a huge number of features, I'd say LEO is a tad simpler.

142
 
 

A high level overview on how zero-copy in iceoryx2 works.

143
144
 
 

Cross-posted from "What would be the best way to store the country of a user in SQL?" by @lena@gregtech.eu in !learn_programming@programming.dev


I use Gorm. This is the current code:

package main

import (
	"fmt"
	"log"

	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

type Env struct {
	DB     *gorm.DB
	Logger *log.Logger
}

type User struct {
	ID           uint
	Username     string
	Name         string
	Email        string
	PasswordHash string
	Country      string //should probably be a foreign key of another table
}

func initDB() {
	env := &Env{}
	db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})
	if err != nil {
		fmt.Printf("Error opening database: %v", err)
		return
	}
	env.DB = db
	env.DB.AutoMigrate(&User{})

}

func main() {
	initDB()
}

As you can see in the comment in the code, I assume the best way would be to have a table of countries and then assign each user to one via a foreign key. However, it seems a bit cumbersome to manually create a list of all countries. Is there a better way to do this?

145
 
 

I have created a new MIDI format to overcome both the limitations of the current one and the unwillingness of the International MIDI Consortium to develop a MIDI 2.0 file format. So I made my own for my game engine. I even added some primitive scripting features.

But here comes the big problem: now I need to develop an editor. While I created a textual representation of it, which is a weird mix of assembly with Lua influences and essentially musical notes and rhythm as values, but eventually it should have a full GUI editor.

The format so far has the following kind of commands:

  • Flow control commands
  • MIDI emit commands which can be either:
    • Note on and off commands
    • Velocity change (aftertouch)
    • Program change
    • Control change
    • Pitch bend
    • A few other less important commands (SysEx, etc.)
  • Commands for the scripting (Arithmetic commands on writable registers, compare and branch, etc.)
  • The ever important wait command, on which the whole system depends, as it tells the sequencer how much clock cycles have to wait between two commands

I have to process these commands for two display widgets, one displays the notes in a piano roll format, one displays any other commands. However, thanks to the way things work, I usually cannot just process MIDI commands directly. For example, notes are defined by a note-on and note-off event (often with aftertouch), no duration. And then comes editing. And then comes to editing around various wait commands. And then comes to editing around various conditional jump commands.

I started to work on a system that converted and separated each command for display, but it's a bit time consuming, and adds extra complexity. But modifying it a bit and adding a "transpiler" to the two systems would make editing pretty easy to implement. I already added "macro"-like features to the textual representation of the format. Could this work?

146
 
 

cross-posted from: https://lemmy.world/post/31184706

C is one of the top languages in terms of speed, memory and energy

https://www.threads.com/@engineerscodex/post/C9_R-uhvGbv?hl=en

147
 
 

From their release page:

  • Updated to target Android 16 (SDK 36)
  • Fixed wallpaper download and apply for wallpapers in assets folder
  • Added support for storing the json file in assets folder
  • Updated dependencies
  • Added support for Global Icon Pack (thanks @RichardLuo0)
148
 
 

OC below by @HaraldvonBlauzahn@feddit.org

What called my attention is that assessments of AI are becoming polarized and somewhat a matter of belief.

Some people firmly believe LLMs are helpful. But programming is a logical task and LLMs can't think - only generate statistically plausible patterns.

The author of the article explains that this creates the same psychological hazards like astrology or tarot cards, psychological traps that have been exploited by psychics for centuries - and even very intelligent people can fall prey to these.

Finally what should cause alarm is that on top that LLMs can't think, but people behave as if they do, there is no objective scientifically sound examination whether AI models can create any working software faster. Given that there are multi-billion dollar investments, and there was more than enough time to carry through controlled experiments, this should raise loud alarm bells.

149
150
view more: ‹ prev next ›