Programming

ljrk,
@ljrk@todon.eu avatar

Coding in again (need to, SDK to $service only available in JS) and I'm frequently using to look up what kind of function I'd use in (foldMap, unzipWith, ...) and then looking for JS packages that implement them.

Am I doing this right?

ljrk,
@ljrk@todon.eu avatar

@greg Unfortunately not, since the actual use-case is to do some additional post-processing (which also changes the type) in case the predicate is true. Basically:

decider deal = if (hasPage) then Left (deal, page Id) else Right (deal)  

So I'm doing two things, partitioning and conditional mapping, ideally in linear time.

greg,

@ljrk ahhhh, now I see. My bad, yea. Hmm.. I'm glad I don't have to write JS :))

gregorni,
@gregorni@fosstodon.org avatar

My #achievements at age 15:

I'm quite proud of myself, to be honest!

HappiePlant,

@gregorni thank you! :)

davidak,
@davidak@chaos.social avatar

@gregorni that are great achievements at any age. At 15, it's impressive! Most people have other interests at that age.

Keep up the good work!

markwyner,
@markwyner@mas.to avatar

Friends in native iOS development. I’d love advice.

I’ve been writing code for over two decades, but never native iOS. Nor C. Nor anything related. But I’m beginning the journey.

Can you recommend a favorite resource for helping folks begin from the ground floor? I can spend all day in an editor and my terminal. But Xcode and iOS is an entirely new world for me.

Thanks in advance!

markwyner,
@markwyner@mas.to avatar

Thanks for all the advice, friends. I appreciate you.

kdapps,

@markwyner I can also recommend these courses by Sean Allen: https://seanallen.teachable.com/p/home

bitbonk,
@bitbonk@mastodon.social avatar

The code that needs to be written to generate complex C# code with source generators becomes hard to read and maintain very quickly.

Wouldn't it make sense to have some sort of templating engine, like Razor or Mustache, but for C# source code?

Maybe it even already exists?

distantcam,
@distantcam@hachyderm.io avatar

@bitbonk I ended up using a custom class to handle indentation, similar to the style of StringBuilder.
https://github.com/distantcam/AutoCtor/blob/main/src/AutoCtor/CodeBuilder.cs

mihamarkic,
@mihamarkic@mastodon.social avatar

@bitbonk I feel you and I'm with you. Hopefully we get something eventually. That also reminds me of decades ago when I used generator. It's still around, but it's not free not updated I think.

michael,
@michael@thms.uk avatar

I don't understand colour contrast calculations:

I got 2 buttons with red background. One with black text, the other with white.

colour contrast ratio with the black on red button is supposedly 4.81, while white on red is only 4.35 (which crucially is below the 4.5 threshold)

Yet, to my eye the white on red is much more legible than black on white.

What am I missing?

GrahamDowns,

@michael I concur. As a person, I find the white on red WAY easier to read.

pkiff,
@pkiff@mastodon.social avatar

@michael I don't think you're missing anything: the formula for calculating colour contrast doesn't always reflect the way we perceive colour.

I'm not an expert (at all!) on this, but I know that the W3C plans to revise the formulas and guidelines for colour in 3.

The new version will analyze "perceptual" contrast instead of just "luminance". And it will account for the "polarity" effect of light text on dark backgrounds.

For a really deep dive, check out:
https://www.smashingmagazine.com/2022/09/realities-myths-contrast-color/

sarajw,
@sarajw@front-end.social avatar

Am I ever... ever going to be able to fundamentally understand what I'm doing? In , or any "modern" framework-based for that matter?

I feel like I'm swimming in a mass of imports, props and hooks and the ((mysterious) => ({ useOf({ so, many }); }, [brackets, braces]);

I know people say knowing the web fundamentals will serve me beyond the current transient trends, but there's such a lot of this particular trend to learn, and frankly, it's paying my bills.

tylersticka,

@sarajw Based on the experiences our team regularly encounters in the wild, a lot of “modern” framework-based developers don’t know what they’re doing either. 😅

I say: Learn just enough to fake competency, rely mostly on vanilla fundamentals, use search engines to fill in the rest!

sarajw,
@sarajw@front-end.social avatar

@tylersticka lolol good. I'll just carry on as I was 😅

elduvelle,
@elduvelle@neuromatch.social avatar

in question:
This should be easy, but I can’t find a straightforward solution anywhere. How can one ask the user to select one **or more ** directories using a graphical interface?

There is “tkFileDialog.askdirectory()” in the Tkinter module but it only allows to select one directory. Any implementations of that function that allow for directory multiselection?
(Yes, I could do a loop and call the same function multiple times but I wouldn’t call that straightforward)

diazona,
@diazona@techhub.social avatar

@elduvelle Somewhat of a nitpick: it might be worth thinking of this more as a <your graphical toolkit> question than a Python question, because it's the toolkit that determines the capabilities of the file chooser, and you might get better suggestions form people who know the toolkit well than from Python developers in general.

jonny,
@jonny@neuromatch.social avatar
gregorni, (edited )
@gregorni@fosstodon.org avatar

One of the things that bug me about Rust is that you never feel like you just finished doing something, you're never "done". In most other languages, after you work on something, you can be quite certain you implemented it in the best way. In Rust, there's always a shorter, built-in or more performant way to do it, and you always have to worry that you didn't use the best possible one.

gregorni,
@gregorni@fosstodon.org avatar

I feel like in Rust, there's often three ways to do something:

  1. The obvious, easy way, which doesn't work because of the borrow checker
  2. The simplest way after that, using built-in functions
  3. The most performant way, which takes twice the amount of code as before for 20% more performance

faassen,
@faassen@fosstodon.org avatar

@gregorni
Perhaps this is because Rust lets you go into the depths a lot further than most languages, while still offering fairly high level abstractions. At some point to make Python code faster you have to write an extension in another language. Rust is one of the languages you can use for that.

But just because you can make some code faster doesn't mean you have to; only if it's not fast enough.

bahmanm,
@bahmanm@mastodon.social avatar

is one of the most underrated and over-avoided tools in the modern programmer's toolbox.
-- Bahman 😎

bahmanm,
@bahmanm@mastodon.social avatar

@EyalL @danb Here's a place to follow the topic of cache/mtime further: https://github.com/bahmanm/bmakelib/issues/58

EyalL,
@EyalL@mastodon.social avatar

@bahmanm @danb some build systems use the content hash to detect changes and precise mtime nanosec value to cache the content hash

(Equality comparison on mtime is safe. Less-than/greater-than is not)

preslavrachev, (edited )
@preslavrachev@mastodon.social avatar

There are two types of Go developers: those who … and those who …

Which one are you?

bmarinov,
@bmarinov@hachyderm.io avatar

@Crocmagnon @preslavrachev this is how I reason about pointer vs value too, as a form of documentation and a hint for developers. For receivers I tend to always end up with pointers anyway so I stick to that. Structs that end up with methods tend to have some form of state. Otherwise the method could've been a func.
Heap vs stack I don't care until someone proves to me that it's an issue.

preslavrachev,
@preslavrachev@mastodon.social avatar

@bmarinov @Crocmagnon both of you have valid points. I am glad that there are other people out there who don't care about stack-heap prematurely.

Just wanted to point out that there is a third category of pointer usage, which has its place: what I call "long-living service objects": https://preslav.me/2023/02/06/golang-do-we-need-struct-pointers-everywhere/#why-use-struct-pointer-types-then Think of a DB connection or a 3rd-part API client. You generally want one single instance of each across the entire app, even though you won't ever mutate it. Thus, the pointer usage.

vascorsd,
@vascorsd@mastodon.social avatar

You may not like it, but hear me out...

For new code using the newer weird white space syntax you should try to configure the formatter to give you 3 spaces as the indent.

It just makes everything better. Go and try 🫣 :catPOWER:

I tried it the other day before turning the newer syntax off completely and it looked much better than 2 spaces.

:blobpeek:

vascorsd,
@vascorsd@mastodon.social avatar

@dwardoric seeing too deep nesting and the code running off the screen to the right kinda screams at you to try and simplify it earlier and to move things to other functions 🤔

vascorsd,
@vascorsd@mastodon.social avatar

@ragb it's easy to mix them. For understanding when and how to use them you need a deep understanding of what they are meant to be used for, which newbies won't know or understand earlier in their career.

It happened a lot having parameters that you want to align and variable declarations and other things, but then having the tab key not expanding automatically to spaces means that you will use it in the middle of code to try to align things accidentally and inherently things will end up mixed.

sos,
@sos@mastodon.gamedev.place avatar

Every single time I check out one of those upcoming shiny new programming languages that claim to be simple:

eniko,
@eniko@peoplemaking.games avatar

@sos the nim guy is an unhinged right wing bigot so that's probably enough of a reason to pass on that one https://peoplemaking.games/@eniko/110652598034999459

sos,
@sos@mastodon.gamedev.place avatar

@eniko Oh that's why the hashtag summoned the trolls.

gregorni,
@gregorni@fosstodon.org avatar

As much as it conflicts with convention, I actually think arrays starting at 1 in Lua is more programmer-friendly.

writeblankspace,
@writeblankspace@fosstodon.org avatar

@gregorni heresy! /s

May I ask why, though?

sonny,
@sonny@floss.social avatar

@gregorni intuitive doesn't mean better :)

fell, (edited )
@fell@ma.fellr.net avatar

I was experimenting with colour distances at work today. I need to find out how similar two colours are, so I wrote a little test program and it was surprisingly pretty.

The algorithm is simple:

  1. Fill the canvas with random colours.
  2. Set the first pixel (top left) to red.
  3. For all pixels, find the most similar pixel and move it next to the current pixel.

To determine the similarity, I calculated the 3D distance in the RGB, HSV and YUV color spaces, which brought very different results. Now, it's quite possible that my HSV and YUV conversion functions were just broken, but that's okay.

(I recommend zooming in!)

fell,
@fell@ma.fellr.net avatar
fell,
@fell@ma.fellr.net avatar

The final conclusion is that simply calculating the distance in RGB space seems to be the fastest and most accurate method to detemine perceived similarity.

kylewritescode,
@kylewritescode@allthingstech.social avatar

Hey my programming friends, I have a question. My daughter is taking a C class in college and is using CLion to write her stuff. One of the comments her professor keeps saying is “remember to work in a Unix environment.”

I’ve always used an IDE when I program so I’m not sure what that means. Anyone able to help?

Thanks 🙏🏼

bluGill,
bluGill avatar

@kylewritescode You should be able to work any ANY environment. I've written code in with just ed before - it is a terrible choice, but it was the only hammer I had available. I've written C on OS/2 (showing my age), MacOS, windows, and several flavors of unix. I know others who have done so on mainframe systems. Some were clearly worse than others, but I got the job done. Do not lock yourself into any one environment!

You do not know what you will do after college so you need to be flexible enough to adjust. That means you should only write standard portable code that runs on any machine where possible. where it isn't possible (mostly user interface classes, but also database) you should use several different machines so that you don't get locked into how one ecosystem does things.

In short, I don't know what your professor means, but I default to assuming they are doing students a disservice.

dgilluly,

@kylewritescode Filesystem benefits? Shared libraries? Less dependence on autocomplete IDE's?

Those are just a few things I can come up with.

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