thtroyer

@thtroyer@programming.dev

This profile is from a federated server and may be incomplete. Browse more on the original instance.

thtroyer,

Oh, nice! I’m going to have to check that out!

thtroyer,

This is probably going to be similar to Apple’s find system, which is a low powered Bluetooth based system. Apple Airtags and powered-off phones just broadcast a “I am here” signal once in a while that other devices can receive and report back to Apple.

thtroyer,

Having used PHP and Java extensively in my career, it’s always entertaining to read what people think about these languages.

Should I use Rust and Go together or just Go?

So I want to make a new project. It will have a website and an algorithm which will handle the requests. The thing is, web development in Rust feels harder than say in Go or Python. So I thought maybe I could somehow make bindings in Rust for Go since the faster the algorithm is, the better. However, that seems to complicate...

thtroyer,

Absolutely.

I’ve seen so many projects hindered by bad decisions around performance. Big things like shoehorning yourself into an architecture, language, or particular tool, but even small things like assuming the naive approach is unacceptably slow. If you never actually measure anything though, your assumptions are just assumptions.

What are the craziest misconceptions you’ve heard about programming from people not familiar with it?

As someone who spends time programming, I of course find myself in conversations with people who aren’t as familiar with it. It doesn’t happen all the time, but these discussions can lead to people coming up with some pretty wild misconceptions about what programming is and what programmers do....

thtroyer,

Based on some places I used to work, upper management seemed convinced that the “idea” stage was the hardest and most important part of any project, and that the easy part is planning, gathering requirements, building, testing, changing, and maintaining custom business applications for needlessly complex and ever changing requirements.

thtroyer,

What? The GPL would have offered no more protection for this exact scenario than the LGPL (or any other license for that matter).

Advice on where to begin with GUI programming?

I realize this is a very broad question, so to help I’ll mention that my primary experience with any programming language is Python. I’ve looked into C and C++ as well, but I haven’t written much in them; in part because they’re more involved, and in part because I get lost in the IDE weeds with’em (whether choosing an...

thtroyer,

While so many things are so much better than they used to be in the programming ecosystem, I feel like entry-level GUI programming is so much worse.

This will probably be an unpopular opinion, but Visual Basic (pre .NET) was one of the easiest ways to make a simple, contemporary (for the time) GUI. Drag and drop some elements, modify the UI properties, double click and add code. It made for an excellent introduction to programming because the UI portions were simple and intuitive enough to stay out of the way.

The rest of VB wasn’t great. Weird language/syntax/keywords keywords, closed environment, mediocre tooling. But for building UIs? I haven’t used anything as easy as that and it’s been over 20 years now…

I don’t have any recommendations unfortunately. Almost everything I do is web based or command line. Web UIs aren’t terrible, but there’s a learning curve and lots of limitations. Haven’t found anything for desktop apps I like lately (last one I built was also with tkinter for a small Python project. Bleh.)

Sublinks Aims to Be a Drop-In Replacement for Lemmy (wedistribute.org)

Seems like an interesting effort. A developer is building an alternative Java-based backend to Lemmy’s Rust-based one, with the goal of building in a handful of different features. The dev is looking at using this compatibility to migrate their instance over to the new platform, while allowing the community to use their apps...

thtroyer, (edited )

Null is terrible.

A lot of languages have it available as a valid return value for most things, implicitly. This also means you have to do extra checking or something like this will blow up with an exception:


<span style="font-style:italic;color:#969896;">// java example
</span><span style="font-style:italic;color:#969896;">// can throw exception
</span><span style="color:#0086b3;">String</span><span style="color:#323232;"> address </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> person.getAddress().toUpperCase();
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">// safe
</span><span style="color:#0086b3;">String</span><span style="color:#323232;"> address </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#183691;">""</span><span style="color:#323232;">;
</span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">(person.getAddress() </span><span style="font-weight:bold;color:#a71d5d;">!= </span><span style="color:#0086b3;">null</span><span style="color:#323232;">) {
</span><span style="color:#323232;">    person.getAddress().toUpperCase();
</span><span style="color:#323232;">}
</span>

There are a ton of solutions out there. Many languages have added null-coalescing and null-conditional operators – which are a shorthand for things like the above solutions. Some languages have removed the implicit nulls (like Kotlin), requiring them to be explicitly marked in their type. Some languages have a wrapper around nullable values, an Option type. Some languages remove null entirely from the language (I believe Rust falls into this, using an option type in place of).

Not having null isn’t particularly common yet, and isn’t something languages can just change due to breaking backwards compatibility. However, languages have been adding features over time to make nulls less painful, and most have some subset of the above as options to help.

I do think Option types are fantastic solutions, making you deal with the issue that a none/empty type can exist in a particular place. Java has had them for basically 10 years now (since Java 8).


<span style="color:#323232;">// optional example
</span><span style="color:#323232;">
</span><span style="color:#323232;">Class Person {
</span><span style="color:#323232;">    private String address;
</span><span style="color:#323232;">    
</span><span style="color:#323232;">    //prefer this if a null could ever be returned
</span><span style="color:#323232;">    public Optional<String> getAddress() {
</span><span style="color:#323232;">        return Optional.ofNullable(address);
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">    
</span><span style="color:#323232;">    // not this
</span><span style="color:#323232;">    public String getAddress() {
</span><span style="color:#323232;">        return address;
</span><span style="color:#323232;">    }
</span>

When consuming, it makes you have to handle the null case, which you can do a variety of ways.


<span style="font-style:italic;color:#969896;">// set a default
</span><span style="color:#0086b3;">String</span><span style="color:#323232;"> address </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> person.getAddress().orElse(</span><span style="color:#183691;">"default value"</span><span style="color:#323232;">);
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">// explicitly throw an exception instead of an implicit NullPointerException as before
</span><span style="color:#0086b3;">String</span><span style="color:#323232;"> address </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> person.getAddress().orElseThrow(</span><span style="color:#0086b3;">SomeException</span><span style="color:#323232;">::new);
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">// use in a closure only if it exists
</span><span style="color:#323232;">person.getAddress().ifPresent(addr </span><span style="font-weight:bold;color:#a71d5d;">-></span><span style="color:#323232;"> logger.debug(</span><span style="color:#183691;">"Address {}"</span><span style="color:#323232;">, addr));
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">// first example, map to modify, and returning default if no value
</span><span style="color:#0086b3;">String</span><span style="color:#323232;"> address </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> person.getAddress().map(</span><span style="color:#0086b3;">String</span><span style="color:#323232;">::toUpperCase).orElse(</span><span style="color:#183691;">""</span><span style="color:#323232;">);
</span>
thtroyer,

Best decision I made was taking an internship. I wasn’t really looking for one, but through some connections, one basically fell in my lap. It was in old tech I messed with in high school, so I was reluctant, but getting real world programming experience was fantastic. The team was great and I helped solve some interesting problems on a small project of theirs. They kept me on as long as they could (>1 year). I think people can be way to idealistic, especially when starting out. Go get a year or two somewhere, anywhere. You’ll have a ton more marketability and control over where you end up with experience and professional references.

Biggest career regret was waiting around afterwards for a time to try to get hired on at that same place. Not a ton of programming jobs locally and I wanted to continue my work there, but the company went through semi-frequent growth/shrink phases, and my team wasn’t able to get me hired in, though they did try for a while. There were plenty of other good things happening in my life during the down-time after this job and before the next, so it’s not really something I regret, but I definitely won’t wait on a company like that again.

thtroyer,

As a normal software dev, I wouldn’t want to work in the games industry at all. There’s plenty of interesting and well paying work in this field.

And then I tinker on the side. I don’t think it’s ever been easier to make your own games as a hobby. So many great tools and resources to learn from. PICO8 has been a blast, but going to learn something more capable soon - not sure if that’ll be Godot, Raylib, or LibGDX yet, but I’ll probably but I’ll probably try prototyping some stuff to figure it out.

thtroyer,

I noticed you don’t have a build/dependency management tool set up. I find having one makes project setup and producing builds much easier, for myself and others.

If you’re interested, I might be able to add Maven to it and submit a PR. :)

thtroyer,

Oh, nice!

Where should I learn kotlin?

I was using freecodecamp’s tutorial on Kotlin but I was told that a video isn’t a good way to learn a language. So I did the hyperskill course but it marks all of my answers as wrong even when the code works, and the subscription for more than ten questions a day is crazy expensive. I will be getting atomic kotlin soon but I...

thtroyer,

Java

My take on a modern Java solution (parts 1 & 2).

spoilerpackage thtroyer.day1; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; public class Day1 { record Match(int index, String name, int value) { } Map numbers = Map.of( “one”, 1, “two”, 2, “three”, 3, “four”, 4, “five”, 5, “six”, 6, “seven”, 7, “eight”, 8, “nine”, 9); /** * Takes in all lines, returns summed answer */ public int getCalibrationValue(String… lines) { return Arrays.stream(lines) .map(this::getCalibrationValue) .map(Integer::parseInt) .reduce(0, Integer::sum); } /** * Takes a single line and returns the value for that line, * which is the first and last number (numerical or text). */ protected String getCalibrationValue(String line) { var matches = Stream.concat( findAllNumberStrings(line).stream(), findAllNumerics(line).stream() ).sorted(Comparator.comparingInt(Match::index)) .toList(); return “” + matches.getFirst().value() + matches.getLast().value(); } /** * Find all the strings of written numbers (e.g. “one”) * * @return List of Matches */ private List findAllNumberStrings(String line) { return IntStream.range(0, line.length()) .boxed() .map(i -> findAMatchAtIndex(line, i)) .filter(Optional::isPresent) .map(Optional::get) .sorted(Comparator.comparingInt(Match::index)) .toList(); } private Optional findAMatchAtIndex(String line, int index) { return numbers.entrySet().stream() .filter(n -> line.indexOf(n.getKey(), index) == index) .map(n -> new Match(index, n.getKey(), n.getValue())) .findAny(); } /** * Find all the strings of digits (e.g. “1”) * * @return List of Matches */ private List findAllNumerics(String line) { return IntStream.range(0, line.length()) .boxed() .filter(i -> Character.isDigit(line.charAt(i))) .map(i -> new Match(i, null, Integer.parseInt(line.substring(i, i + 1)))) .toList(); } public static void main(String[] args) { System.out.println(new Day1().getCalibrationValue(args)); } }

thtroyer,

Project Panama is aimed at improving the integration with native code. Not sure when it will be “done”, but changes are coming.

thtroyer,

Nice video about it here : youtu.be/cZLed1krEEQ

Tldw: US DOS version actually has 2 separate impossible jumps on a level that aren’t present on the European DOS or NES versions.

thtroyer,

Wow, that looks really nice!

I use Lua for PICO-8 stuff and it works well enough, but certain parts are just needlessly clumsy to me.

Looks like TIC-80 supports wren. Might have to give that a try sometime!

What are some of the best optimizations you applied to your code?

Got myself a few months ago into the optimization rabbit hole as I had a slow quant finance library to take care of, and for now my most successful optimizations are using local memory allocators (see my C++ post, I also played with mimalloc which helped but custom local memory allocators are even better) and rethinking class...

thtroyer, (edited )

I’ve got so many more stories about bad optimizations. I guess I’ll pick one of those.

There was an infamous (and critical) internal application somewhere I used to work. It took in a ton of data, putting it in the database, and then running a ton of updates to populate various fields and states. It was something like,

  • Put all data in x table with batch y.
  • Update rows in batch y with condition a, set as type a. (just using letters as placeholders for real states)
  • Update rows in batch y that haven’t been updated and have condition b, set as type b.
  • Update rows in batch y that haven’t been updated and have condition c, set as type c.
  • Update rows in batch y that have condition b and c and condition d, set as type d.
  • (Repeat many, many times)

It was an unreadable mess. Trying to debug it was awful. Business rules encoded as a chain of sql updates are incredibly hard to reason about. Like, how did this row end up with that data??

Me and a coworker eventually inherited the mess. Once we deciphered exactly what the rules were and realized they weren’t actually that complicated, we changed the architecture to:

  • Pull data row by row (instead of immediately into a database)
  • Hydrate the data into a model
  • Set up and work with the model based on the business rules we painstakingly reverse engineered (i.e. this row is type b because conditions x,y,z)
  • Insert models to database in batches

I don’t remember the exact performance impact, but it wasn’t markedly faster or slower than the previous “fast” SQL-based approach. We found and fixed numerous bugs, and when new issues came up, issues could be fixed in hours rather than days/weeks.

A few words of caution: Don’t assume that building things with a certain tech or architecture will absolutely be “too slow”. Always favor building things in a way that can be understood. Jumping to the wrong tool “because it’s fast” is a terrible idea.

Edit: fixed formatting on Sync

thtroyer,

Yep, absolutely.

In another project, I had some throwaway code, where I used a naive approach that was easy to understand/validate. I assumed I would need to replace it once we made sure it was right because it would be too slow.

Turns out it wasn’t a bottleneck at all. It was my first time using Java streams with relatively large volumes of data (~10k items) and it turned out they were damn fast in this case. I probably could have optimized it to be faster, but for their simplicity and speed, I ended up using them everywhere in that project.

Are IDEs mostly bloatware?

Hi experienced devs , I am a beginner programmer. I mostly use code completion and go-to source , and rename function and objects, code-pretty. Other features not so much. What features do you use often And what features are not that useful in an IDE and can be considered bloat? P.S.- Which is that one feature that you can’t...

thtroyer,

I’m reluctant to call much “bloat”, because even if I don’t use something doesn’t mean it isn’t useful, to other people or future me.

I used to code in vim (plus all sorts of plugins), starting in college where IDEs weren’t particularly encouraged or necessary for small projects. I continued to use this setup professionally because it worked well enough and every IDE I tried for the main language I was using wasn’t great.

However, I eventually found IDEs that worked for the language(s) I needed and I don’t have any interest in going back to a minimalistic (vim or otherwise) setup again. It’s not that the IDE does things that can’t be done with vim generally, but having a tool that understands the code, environment, and provides useful tooling is invaluable to me. I find being able to do things with some automation (like renaming or refactoring) is so much safer, faster, and enjoyable than doing it by hand.

Features I look for/use most often:

  • Go to (both definition and usages)
  • Refactor tooling (renaming, inlining, extracting, etc).
  • Good warnings, along with suggested solutions. Being able to apply solution is a plus.
  • Framework integrations
  • User-friendly debugger. Ability to pause, drill in, and interact with data is immensely helpful with the type of applications I work on.
  • Configurable breakpoints.
  • Build tool integrations. Doing it on the console is… fine… but being able to set up what I need easily in the IDE is preferable.

Features I don’t use or care so much about? Is there much left?

  • My IDE can hook up to a database. I’ve tried it a few times, but it never seemed particularly useful for the apps I work on.
  • git integration. I have a separate set of tools I normally work with. The ones in my IDE are fine, but I usually use others.
  • Profiler. I use it on occasion, but only a few times a year probably.

I do code in non-IDE environments from time to time, but this is almost always because of a lack of tooling than anything else. (Like PICO-8 development)

thtroyer,

I think that’s a fair argument. PICO-8 definitely could be called a primitive IDE. I think it’s closer to being a primitive game engine with so much of its focus being on graphics and sound tooling.

While you can code simple things within PICO-8, I’ve found that as I’ve built bigger things, I work better in an outside editor, even if it only gets me smaller fonts, splitable windows, vim bindings, limited linting, and somewhat broken code completion.

This isn’t a criticism of PICO-8 as an environment. I think there are a lot of strengths in its simplicity, especially for beginner coders.

I tend to make a distinction between a customizable editor with some support for a language (like vim+plugins) vs a dedicated all-in-one tool that fully understands the language and environment (IDE). PICO-8 is hard to place on that spectrum given it’s an all-in-one tool, but switching to a modified editor gives you more features.

thtroyer,

This is a very strange article to me.

Do some tasks run slower today than they did in the past? Sure. Are there some that run slower without a good reason? Sure.

But the whole article just kind of complains. It never acknowledges that many things are better than they used to be. It also just glosses over the complexities and tradeoffs people have to make in the real world.

Like this:

Windows 10 takes 30 minutes to update. What could it possibly be doing for that long? That much time is enough to fully format my SSD drive, download a fresh build and install it like 5 times in a row.

I don’t know what exactly is involved in Windows updates, but it’s likely 1) a lot of data unpacking, 2) a lot of file patching, and 3) done in a way that hopefully won’t bork your system if something goes wrong.

Sure, reinstalling is probably faster, but it’s also simpler. If your doctor told you, “The cancer is likely curable. Here’s the best regimen to get you there over the next year”, it would be insane to say, “A YEAR!? I COULD MAKE A WHOLE NEW HUMAN IN A YEAR!” But I feel like the article is doing exactly that, over and over.

thtroyer,

I might be wrong, but the 2nd case looks like an anti pattern, the loop switch sequence .

The last case looks the most readable to me. Always start with that unless there’s a clear reason not to (eg inefficient multiple nested loops).

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • kavyap
  • DreamBathrooms
  • khanakhh
  • magazineikmin
  • InstantRegret
  • tacticalgear
  • thenastyranch
  • Youngstown
  • rosin
  • slotface
  • modclub
  • everett
  • ngwrru68w68
  • anitta
  • Durango
  • osvaldo12
  • normalnudes
  • cubers
  • ethstaker
  • mdbf
  • provamag3
  • GTA5RPClips
  • cisconetworking
  • Leos
  • tester
  • megavids
  • lostlight
  • All magazines