There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

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

kronicmage , in We did this to ourselves

This is referencing Philip Wadler’s 1989 paper “Theorems for Free”, which is fairly well known in the Haskell community: home.ttic.edu/~dreyer/course/papers/wadler.pdf

spicyemu ,

That looks like something I’ve seen somewhere and didn’t understand.

Speiser0 , (edited ) in thisIsGoingToBeASeriousDebate

Definitely left. Right one won’t be optimized. (And there are so many some mistakes in your inline asm…)

TadoTheRustacean OP ,

What mistakes?

Speiser0 ,

Mostly the missing listing of clobbered registers. Other than that it’s mostly just that you’re doing useless things, like manually putting the stuff into the registers instead of letting the compiler do it, and the useless push and pop. And the loop is obviously not needed and would hurt performance if you do every write like that.


<span style="color:#323232;">asm!(
</span><span style="color:#183691;">"syscall"</span><span style="color:#323232;">,
</span><span style="font-weight:bold;color:#a71d5d;">in</span><span style="color:#323232;">(</span><span style="color:#183691;">"rax"</span><span style="color:#323232;">) </span><span style="color:#0086b3;">1</span><span style="color:#323232;">,
</span><span style="font-weight:bold;color:#a71d5d;">in</span><span style="color:#323232;">(</span><span style="color:#183691;">"rdi"</span><span style="color:#323232;">) </span><span style="color:#0086b3;">1</span><span style="color:#323232;">,
</span><span style="font-weight:bold;color:#a71d5d;">in</span><span style="color:#323232;">(</span><span style="color:#183691;">"rsi"</span><span style="color:#323232;">) text_ptr,
</span><span style="font-weight:bold;color:#a71d5d;">in</span><span style="color:#323232;">(</span><span style="color:#183691;">"rdx"</span><span style="color:#323232;">) text_size,
</span><span style="color:#323232;">
</span><span style="color:#323232;">)
</span>

(“so many” was inappropriate, sorry.)

TadoTheRustacean OP ,

I am hopeless at getting the text_ptr simpler than i64::from_str_radix(&format!(“{:p}”, my_string)[2…], 16).unwrap(); How can i get it the normal way?

Speiser0 ,

Just use str::as_ptr().

Here’s an example (disclaimer: I haven’t used inline asm in rust before, expect issues): godbolt.org/z/sczYGe96f

PotatoesFall , in We did this to ourselves

I need an explainer on this one

steersman2484 ,

<span style="color:#323232;">if (theorems_for(free))
</span><span style="color:#323232;">    make_instance_of(x, String)
</span>
ezchili ,

What

db2 ,

Magnets.

deegeese ,

It’s a miracle!

RoyaltyInTraining ,
@RoyaltyInTraining@lemmy.world avatar

How do they work?

remotelove , in Hobbyte

Hobbword doesn’t quite work, does it?

Davel23 ,

No, but I think "Hobnibble" is something...

yum13241 ,

What about Hoblong? Or Hobshort. Or HobIEEE-floating-point.

apprehentice , in We did this to ourselves

Okay, but what’s a theoren?

Pok ,

It may or may not be a string.

jasondj , in We did this to ourselves

I’m sorry, I’m only a novice Python guy. Know enough to get two RESTful APIs to talk to each other and do some network automation or rudimentary Ansible plugins.

What’s wrong with if isinstance(x, str):?

Knusper ,

Apparently, “Theorems for free!” is a paper that talks about an extensive ability to reason about parts of programs, if you follow some rather basic rules.

However, lots of popular programming languages throw this ability out the window, because they do not want to enforce those basic rules.
Most languages, for example, allow for rather uncontrolled side effects and to be able to reason as a programmer, you have to make the assumption that no one else abused side effects.

The instanceof is rather referring to dynamic typing, though, as e.g. employed by Python and JS, which makes it difficult to make any assumptions at all.

So, in statically typed languages, when you’re implementing a function, you can declare that a given parameter is a number or a string etc. and the compiler will enforce that for you. In dynamically typed languages, you have to assume that anyone calling your function is using it correctly, which is a difficult assumption to make after a refactoring in a larger codebase.

All in all, such different levels of rigorosity can be fine, but the larger your codebase grows, the more you do want such rules to be enforced, so you can just ignore the rest of the codebase.

MNByChoice , in poorPenguin

I hate those messages. Just be class clear about the failure.

OTOH, keep up the good fight little computer.

yum13241 ,

The first 2 are exactly that. The third one is just a funny status update.

Swiggles ,

It kinda is though. Iirc it received an interrupt it shouldn’t have received and doesn’t know how to resolve. It is not supposed to ignore it, but then the only other option is crashing at this point. Basically it continues in a dazed and confused state.

Of course the message could be clearer, but at least it also makes the message easily searchable.

r00ty Admin , in They used coding and algorithms
r00ty avatar
function goingToCrashIntoEachother()
{
    // NYI
    return false;
}
odium ,

//TODO: implement logic

ChaoticNeutralCzech ,

<span style="color:#323232;">//tested: 100% working on actual drone
</span>

– You mean drones, right?

nxdefiant ,

unittest 100% complete, story closed.

guycls ,

Ship it!

ChickenLadyLovesLife , in They used coding and algorithms

And they were roommates!

MonkderZweite , (edited ) in thisIsGoingToBeASeriousDebate

plan 9 cat vs GNU longcat meme

edit: reddit image linking is broken?

AMDIsOurLord ,

Well, the GNU version does more and is more documented. The Plan9 code is frankly shitC, even for 1980z

But this monstrosity is something else

MonkderZweite ,

Of course, not always is shorter better.

257m ,

Plan 9 does the job. GNU is better for the end user. But if I had to maintain that stuff I would definitely want to maintain the Plan 9 code and not the GNU code.

rhpp ,

reddit image linking is broken?

Well you didn’t link to a reddit image, you linked to Google image search result page which is not an image.

MonkderZweite ,

I did that because the image didn’t show in reddt.

rhpp ,

Looks like you need to insert the raw image link, not Reddit’s media wrapper link.

plan 9 cat vs GNU longcat meme

MonkderZweite ,

Oh, so it’s only my browser setup that doesn’t show it.

257m , (edited ) in thisIsGoingToBeASeriousDebate

<span style="color:#323232;">#include &lt;stdio.h>
</span><span style="color:#323232;">
</span><span style="color:#323232;">int main(int argc, char** argv)
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    printf("hello, world");
</span><span style="color:#323232;">}
</span>
kronicmage , in We did this to ourselves

This is referencing Philip Wadler’s 1989 paper “Theorems for Free”, which is fairly well known in the Haskell community: home.ttic.edu/~dreyer/course/papers/wadler.pdf

Cwilliams , in thisIsGoingToBeASeriousDebate

I thought the whole point of rust macros was to abstract away the scary asm at zero cost!

CodexArcanum , in D or d come on

I love how many people brought up the Turkish “I” as if everyone here is on the Unicode steering committee or just got jobs for Turkish facebook.

I, an English speaker, have personally solved the problem by not having a Turkish I in the name of my Downloads directory, or any other directory that I need to cd into on my computer. I’m going to imagine the Turks solve it by painstakingly typing the correct I, or limiting their use of uppercase I’s in general.

In fact, researching the actual issue for more than 1 second seemingly shows that Unicode basically created this problem themselves because the two I’s are just seperate letters in Turkic languages. …wikipedia.org/…/Dotted_and_dotless_I_in_computin…

If you nerds think this is bad try doing Powershell for any amount of time. It is entirely case-insensitive.

yum13241 ,

Why the FUCK did they make characters that look the same have different codepointers in UNICODE? They should’ve done what they did in CJK and make duplicates have the same codepointer.

Unicode needs a redo.

Tranus ,

Well letters don’t really have a single canonical shape. There are many acceptable ways of rendering each. While two letters might usually look the same, it is very possible that some shape could be acceptable for one but not the other. So, it makes sense to distinguish between them in binary representation. That allows the interpreting software to determine if it cares about the difference or not.

Also, the Unicode code tables do mention which characters look (nearly) identical, so it’s definitely possible to make a program interpret something like a Greek question mark the same as a semicolon. I guess it’s just that no one has bothered, since it’s such a rare edge case.

yum13241 ,

Why are the Latin “a” and the Cryilic “a” THE FUCKING SAME?

mrpants ,

In cases where something looks stupid but your knowledge on it is almost zero it’s entirely possible that it’s not.

The people that maintain Unicode have put a lot of thought and effort into this. Might be helpful to research why rather than assuming you have a better way despite little knowledge of the subject.

yum13241 ,

When it’s A FUCKING SECURITY issue, I know damn well what I’m talking about.

mrpants ,

Again you do not because the world consists of more than your interests and job description.

yum13241 ,

I know damn well what I’m talking about when someone could get scammed on “apple.com” but with a Cyrillic A.

mrpants ,

You know the problem but not the set of reasonable or practical solutions.

Anyways I and l look identical too in many fonts. Should we make them the same letter?

yum13241 ,

No, but that’s what Unicode does.

The solution is to force font creators to be fucking reasonable, just like how the Cyrillic A looks exactly like the Latin A. They are the same letter. The letters L and I are totally different (in handwriting at least)

They already did that for CJK. Make characters that look the same in handwriting b have be same codepointer.

kattfisk ,

I and l also look identical in many fonts. So you already have this problem in ascii. (To say nothing of all the non-printing characters!)

If your security relies on a person being able to tell the difference between two characters controlled by an attacker your security is bad.

yum13241 ,

The problem is when you can register “apple.com” with the Cryillic A, fooling many.

The I l issue is caused by fonts, not by ASCII.

kattfisk ,

You really can’t though. For several reasons. Which would have been apparent to you had you bothered to actually create your example link to аpple.com or to understand this problem.

30p87 , in thisIsGoingToBeASeriousDebate

Personally,


<span style="color:#323232;">echo Hello World!
</span>
pranaless ,

<span style="font-weight:bold;color:#a71d5d;">use </span><span style="color:#323232;">std::process::Command;
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">fn </span><span style="font-weight:bold;color:#795da3;">main</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    Command::new(</span><span style="color:#183691;">"sh"</span><span style="color:#323232;">)
</span><span style="color:#323232;">        .</span><span style="color:#62a35c;">arg</span><span style="color:#323232;">(</span><span style="color:#183691;">"-c"</span><span style="color:#323232;">)
</span><span style="color:#323232;">        .</span><span style="color:#62a35c;">arg</span><span style="color:#323232;">(</span><span style="color:#183691;">"echo Hello World!"</span><span style="color:#323232;">)
</span><span style="color:#323232;">        .</span><span style="color:#62a35c;">spawn</span><span style="color:#323232;">()
</span><span style="color:#323232;">        .</span><span style="color:#62a35c;">unwrap</span><span style="color:#323232;">();
</span><span style="color:#323232;">}
</span>

Like this?

30p87 ,

No, more like


<span style="color:#323232;">use std::process::Command; fn main() { Command::new("sh").arg("-c").arg("echo Hello World!").spawn().unwrap(); }
</span>

.
Just a little bit shorter, as it seems /s

funkajunk ,
@funkajunk@lemm.ee avatar

I just fucking threw up

30p87 ,

I did too. Multiple times in fact, I had to look at the other Rust code!

TadoTheRustacean OP ,

Isn’t echo a shell builtin?

pranaless ,

Yes and no. While coreutils does provide an echo binary, shells also have a built-in for optimisation purposes.

At first I had the code calling the binary directly, but then changed it to spawning a shell (and so using the builtin). It’s very cursed either way.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • [email protected]
  • lifeLocal
  • goranko
  • All magazines