programming

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

Opafi, in [Blog] Can Rust prevent logic errors?

I really don’t get the article. It’s not the compiler’s purpose to prevent logic errors nor does it do that properly. Trying to overcomplicate your types to the degree where they prevent a few of them at the cost of making your code less flexible concerning potential future issues doesn’t sound like a good idea either.

What’s wrong with tests? Just write tests to see if your code does what it’s expected to do and leave the compiler for what it’s made for.

potterman28wxcv, (edited )

Why would you have to choose between tests and compiler checks? You can have both. The more you have the less chance of finding bugs.

I would also add that tests cannot possibly be exhaustive. I am thinking in particular of concurrency problems - even with fuzzing you can still come across special cases where it goes wrong because you forgot a mutex somewhere. Extra static checks are complementary to tests.

I think you can write “unsafe” code in Rust that bypass most of the extra checks so you do have the flexibility if you really need it.

TehPers,

My favorite tests are the ones I don’t need to remember to write. I haven’t needed to write a test for what happens when a function receives null in a while thanks to TS/mypy/C#'s nullable reference types/Rust’s Option/etc. Similarly, I generally don’t need to write tests for functions receiving the wrong type of values (strings vs numbers, for example), and with Rust, I generally don’t even need to write tests for things like thread safety and sometimes even invalid states (since usually valid states can be represented by enum variants, and it’s often impossible to have an invalid state because of that).

There is a point where it becomes too much, though. While I’d like it if the compiler ensured arbitrary preconditions like “x will always be between 2 and 4”, I can’t imagine what kinds of constraints that’d impose on actually writing the code in order to enforce that. Rust does have NonZero* types, but those are checked at runtime, not compile time.

potterman28wxcv,

There are techniques like abstract interpretation that can deduce lower and upper bounds that a value can take. I know there is an analysis in LLVM called ValueAnalysis that does that too - the compiler can use it to help dead code elimination (deducing that a given branch will never be taken because the value will never satisfy the condition so you can get rid of the branch).

But I think these techniques do not work in all use cases. Although you could theoretically invent some syntax to say “I would like this value to be in that range”, the compiler would not be able to tell in all cases whether it’s satisfied.

If you are interested in a language that has subrange checks at runtime, Ada language can do that. But it does come at a performance cost - if your program is compute bound it can be a problem

robinm, in CSS is fun again

This new OKLCH color space looks really nice to use. It’s surprising that it’s really human readable, I wouldn’t have guessed that you could do it for random colors.

I’m a bit surprised. Why does OKLAB gradiant looks better than OKLCH?

Paradox,
@Paradox@lemdro.id avatar

They can both model any color equally well, it’s just oklch works even closer to how we perceive colors changing. LAB and all derivatives are in Cartesian space, with luminance, a, and b being the defining axises. Luminance is self explanatory, but a and b are just axises of how much red/green and blue/yellow there is. It can be difficult to think of a color in how much blue it is, for example, when the color is something like nearly pure red. They both affect the hue output, so varying one can create strange, unintuitive colors

LCH works in polar space, like a color wheel. L is still luminance, c is the “colorfulness” and h is the hue. H and C let you set the same values a and b would, but in a more human way. We’re used to thinking about colors changing independent of how much of a color there is, and that’s what LCH does. Vary only the h and you get very different colors. Vary only the c and you get the same color but in different amounts of saturation, from full color to no color

mojo, in CSS is fun again

It didn’t change

flying_sheep, in CSS is fun again
@flying_sheep@lemmy.ml avatar

Finally there’s a way to have gradients that don’t look like shit.

Defining them to interpolate in a suitable color space instead of the completely inappropriate sRGB is great!

theComposer, in CSS is fun again

🌍👨‍🚀🔫👨‍🚀

Always has been.

luciole, in CSS is fun again
@luciole@beehaw.org avatar

We’re definitely lightyears away from that cursed era of building layouts with float.

1984, in CSS is fun again
@1984@lemmy.today avatar

Naah.

Aatube, in Free software pioneer Stallman reveals cancer diagnosis
@Aatube@kbin.social avatar

This is VERY old news.

beepnoise, in Free software pioneer Stallman reveals cancer diagnosis

RMS has been a divisive figure in the FOSS community, but I don’t think anyone deserves cancer.

Hope he fights through it and comes out of the other side well and healthy.

ag_roberston_author, in How to add hard-coded website to square space?
@ag_roberston_author@beehaw.org avatar

Try porkbun. They have static hosting options, including to host from a GitHub repo.

krash, in This took me 4 months

Congrats on the release! Had this been made from scratch, without any underlying libraries that’ll convert images to ASCII?

Vitaly,
@Vitaly@feddit.uk avatar

from scratch, you can check used library in Cargo.toml if you want

Quexotic, in How to add hard-coded website to square space?

They’re supposed to have amazing customer service. Ask them. I bet good money that you can’t do what you’re trying to do though. Best of luck to you.

reric88,
@reric88@beehaw.org avatar

Thanks! I kind of figured it out after a lot of searching and trial and error.

I removed all but one page, and removed all content on that page. In website settings, there’s an option for “code injection”. This is where I pasted all my code, but I had to do it in a weird way.

I built the website with React, and each page was it’s own component. I had to build the project, and then take all of the JS created from the build process and wrap them in script tags, and wrap the CSS in style tags. Then I had to make a div with an id of root within the code injection body. Afterwards, I copied and pasted all the JS and CSS under the root div.

It’s not perfect and I need to tweak some things, but the site is 90% intact.

Quexotic,

That… That’s a lot.

I’m glad you figured it out. I think I would have switched services.

kambusha, in How to add hard-coded website to square space?

Can’t comment on square space, but you could maybe try firebase (google), github pages, or netlify as alternatives?

GammaGames,

You can (or at least could ~5 years ago) easily serve a static site through an s3 bucket

MJBrune,

Now you can just host static websites for free on gitlab/github.

GammaGames,

True, though I think GutHub does need a paid account if you want the repo to be private

MJBrune,

Yeah, I mean if it’s a static website unless it’s using a generator, the source is accessible by just visiting the website. So having it public shouldn’t matter too much, right? Even if it’s using a generator, it’s not like what you are writing is secret. That said I use GitLab and Hugo on a private repo. I have no reason to make it public and all the highly experienced web developers told me it simply doesn’t need to be public so why make it public?

GammaGames,

Good point! I rarely use plain static pages, there’s usually some templating involved if I’m going through GH pages.

Yoruio,

netlify is amazing for static sites.

catacomb,

Just to throw out another one, there’s also Cloudflare Pages.

reric88,
@reric88@beehaw.org avatar

I actually started looking at firebase today. I’m confused by it, but that’s the case with everything new to me.

kambusha,

You’ll want to create a new firebase project, install the firebase CLI on your computer and then use the CLI to: login to firebase, select the project you created, and then using the CLI run firebase deploy wherever your code is. That should use firebase “hosting” to serve your static files.

I find Google Cloud’s documentation extremely confusing (including firebase), so you’re not alone on that front. Took a lot of searching & troubleshooting to finally get my setup working as I intended.

Scary_le_Poo, in In the defence of Object-Relational Mappers
@Scary_le_Poo@beehaw.org avatar

Defense doesn’t have a c in it.

cwagner,

You should send that information to the non-native English speaker that wrote the blog. Might as well go ahead and gather all the other typos he did.

Scary_le_Poo,
@Scary_le_Poo@beehaw.org avatar

how do you, yourself, differentiate a typo from a misspelling?

cwagner,

I don’t.

ergoplato,
@ergoplato@neurodifferent.me avatar

@Scary_le_Poo @cwagner it does in British English. American English is so weird.

Scary_le_Poo,
@Scary_le_Poo@beehaw.org avatar

Oh interesting, never knew that. In some instances american english is better, in others, british is better, in still others, the aussies perfected it. I suggest we combine for a master dialect.

Kolanaki,
@Kolanaki@yiffit.net avatar

We should’st hie back to corky English

shortwavesurfer, in issues with bash commands as variables

Here, you guys can go laugh at my code now.

monero.town/post/898585

bizdelnick,

Again, you don’t need sed for this, simply set scale=2 or how many digits after decimal point you need. Also you missed ! in the shebang (#!/bin/bash or #!/bin/sh).

shortwavesurfer,

So I need five digits after the decimal point, but then when I do the multiplication, I only want four digits in total. I did move “scale=” to five and that made the sed command in rmdec much shorter, but its still needed. I thought i could add “length=4” but that throws an error.

bizdelnick,

Multiply before you divide to keep precision: 1000 * $i1p / $apiresponse

shortwavesurfer,

Ah, that did the trick. Thanks

bizdelnick,

And again, using here-document greatly improves readability, like this.

shortwavesurfer,

Hmm. I had a look at the example given. I see the idea, but would cat be the thing to use or would it be echo <<-EOF > “$file”?

bizdelnick,

You need cat because it reads stdin and prints it to stdout. echo does not read stdin, it prints its arguments.

shortwavesurfer,

I have never used cat like that before. If you just ent cat abcd > file it says abcd doesnt exist but does create “file”. I know you can cat contents of a file into another file but why the <<-EOF > file works is a bit beyond me.

bizdelnick,

cat does not create file, your shell does when you redirect the standard output with > file.

shortwavesurfer,

Alright, I modified it and formatted it. However, for whatever reason, the output HTML in /var/www/html/index.html does not keep the formatting and is all just left aligned as before. That’s not really a problem, just more of a curiosity as to why it did not inherit the formatting of the input.

bizdelnick,

When using “<<-”, shell removes all tabs from the beginning of each line. So you have to use tabs for formatting inside your script and then spaces for HTML formatting, as in my example. Or use “<<” without dash to preserve tabs.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • Socialism
  • KbinCafe
  • TheResearchGuardian
  • Ask_kbincafe
  • oklahoma
  • feritale
  • SuperSentai
  • KamenRider
  • All magazines