programmer_humor

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

Plibbert, in Good luck web devs
lurch,

They put touchscreens on doorstops now? /s

xmunk,

Java truly runs on everything.

LilB0kChoy,

Embrace the power of the pyramid.

fl42v,

Ackchuwally, that’s a prism 🙃

lseif,

ackshuaelly, it says ‘pyramid’ right there

fl42v,

I’ve noticed… But it lies

NoisyFlake,

Unleash the power of the pyramid!

Bye, in The Holy Trinity of JavaScript

I don’t work with web stuff, why is js so weird? Can you write a website in other languages, like c# or python?

fiah,
@fiah@discuss.tchncs.de avatar

Can you write a website in other languages, like c# or python?

sure, as long as it compiles to javascript

Bye,

But the browser can’t handle other languages? That seems a bit silly

Anafabula,
@Anafabula@discuss.tchncs.de avatar

If they could, JavaScript wouldn’t be nearly a popular

pankkake,
@pankkake@lemmy.world avatar

There’s a push towards WebAssembly. Officially it’s not supported yet, but most browsers can handle it. I don’t know how mature the project is though.

But yeah, essentially everything on the web is JS.

Static_Rocket,
@Static_Rocket@lemmy.world avatar

Even webassembly needs a JS stub loader right now. I still can’t believe that’s a requirement.

Ephera,

Sure, but you can get frameworks that generate that for you. I’ve written whole webpages in WASM without writing any JS.

You don’t get around reading JS documentation, though. Especially the DOM API is just documented as JS, and you basically hope that your framework makes it obvious enough how to write that in your non-JS language of choice.

Static_Rocket,
@Static_Rocket@lemmy.world avatar

This is exactly the reason why I can’t believe that was ever a requirement. I would have crazy respect for webassembly if it could stand on it’s own as it would allow people to completely move away from JS, but if JS is still in the stack in any way it will introduce a (even if it is minimal) compatibility and maintenance cost in the long run.

Ephera,

I used to think so, too, but on the one hand, the DOM API is absolutely massive. Going through the standardization, implementation and documentation process another time would take decades.

And on the other hand, a language-agnostic API in WebAssembly would mean specifying it WebAssembly itself. And well, it’s Assembly-like, so what’s currently a single line for calling a JS function would turn into tens of lines of low-level code.

Ultimately, you’d want code from some other high-level language to give you a summary of how you may need to call your language-specific wrapper. In practice, that’s likely even worse than translating it from JS, because the high-level call isn’t standardized.

lseif,

i believe they plan to remove that requirement? at least i know they are trying to use a native wasm<->dom api instead of wasm<->js<->dom, which is slow

Static_Rocket,
@Static_Rocket@lemmy.world avatar

Big if true, do you have a link to follow that development? I’ve been curious about some languages that compile to JS+WASM but I’ve been waiting for something like this to finally cut out the middle man and give me an excuse to learn WASM directly.

lseif,

its just what i have heard.

Stumblinbear,
@Stumblinbear@pawb.social avatar

:)

mindbleach,

When you see the entire world agree to one standard about anything, leave it the fuck alone.

Ephera,

There’s actually in theory all the pieces in place to use a different scripting language, because in the early days, there really were multiple. But yeah, the massive DOM API is only really standardized+implemented+documented for JS, so you don’t get around it in the end.

As the others said, though, WebAssembly is starting to become a thing and the JS boilerplate for calling the DOM API can be generated for you.

thanks_shakey_snake,

Most of the weirdness comes from being designed for the web, and specifically for working with forms. The value of a form field will always be a string, which is a simple and straightforward idea, but then the trouble showed up when we tried to make it more convenient to work that way.

cmdrkeen,

Actually, most of the weirdness comes from having been originally designed in a matter of 10 days by a single engineer working to accommodate a tight release schedule.

thanks_shakey_snake,

I mean, do you think that has more explanatory power though? The type coercion rules are actually more elaborate with == than necessary for equality checking, because it was intended as a clever convenience for working with strings. If it was really all about the short timeline, wouldn’t you just skip that and do a more straightforward equality comparison, like the algorithm that === implements?

Besides, it’s not like everything in the language was conceived and implemented in those 10 days. The language has been evolving steadily since then. I’m not even sure if the modern == comparison algorithm worked that way in the first iteration.

Personally, I find it more useful to understand the context that lets me say “that’s a quirky consequence of a sensible principle,” rather than blaming it on the “ten days” legend generically.

BatmanAoD,

I think the “ten days” explanation has the merit of being charitable, because it implies that Brendan Eich wouldn’t have made such short-sighted design choices under more favorable circumstances.

(I do not believe that it’s a “sensible principle” to treat text as such a fundamental form of data that a basic language feature like the equality operator should be entirely shaped around it. Surely the consequences of building an entire language around text manipulation should be apparent by considering how awkward Posix-style shells are for any nontrivial scripts.)

thanks_shakey_snake,

Well… The circumstances were that he was asked to whip up a little scripting language, that felt a little like Java and a little like Scheme, which could be used to add simple manipulations and interactions to web pages. Specifically to web pages. Not webservers, mobile apps, databases, banking systems, physics simulations, robotics… Only web pages. And nobody had even conceived yet of something like Google Sheets-- It was simple HTML forms and DOM manipulation.

IMO in that context, it makes alot of sense. I think it was probably still the wrong decision-- definitely with the benefit of hindsight, and quite possibly even at the time, even in that narrow context. Way more trouble than it’s worth.

But it’s beneficial to know that there was a principled (if misguided) reason behind it, that ties into the nature and history of the language-- It’s not simply “dude was in a hurry and not thinking.” Both are kinda true, but the former perspective helps us understand something useful, whereas the latter doesn’t get us anywhere interesting.

cmdrkeen,

TBF he probably had know way of knowing that the language he was creating would one day end up being as popular as it is now.

I guess the moral of the story is that you can never really predict what long term consequences your decisions might have down the road.

Vent,

What software isn’t?

nintendiator,

Can you write a website in other languages, like c# or python?

Yeah, anything that outputs HTML and CSS can do so. There’s a module for Apache to write webpages in Python (libapache-mod-python) and I’m p sure someone somewhere made a module to do it in Rust already except they’re infighting over whether tag parsing in it should be marked unsafe.

For that matter you do can write web pages in your shell eg.: bash, that’s what CGI is all about.

wabafee, (edited )

I guess why it’s weird because of the loose rules it follows, like what is mentioned about === and ==. There is WebAssembly which kinda acts like Javabyte code or CIL there used to be huge hype that it’s going to replace JavaScript, though it’s not used that much today. I think why there is low adoption is mainly because JavaScript is good enough, it’s widespread and easy to learn.

DarkGamer, in 4 billion if statements
@DarkGamer@kbin.social avatar

This is why every programmer needs to understand the modulo operator.

MxM111,
@MxM111@kbin.social avatar

I would divide by two (floating point) and check the fractional part.

sus,

turns out that 2^53 + 1 is an even number

iknowitwheniseeit,

The article only covers unsigned 32-bit numbers, so floating point division would be fine.

jaybone,

Or bitwise AND.

Reptorian,

This is what I prefer too! I also some times prefer to use bitshift when it comes to division or multiplication of power of 2.

backhdlp, in This is what being a Redditor does to your life
@backhdlp@lemmy.blahaj.zone avatar

Me when I don’t know at how many changes I should commit (the previous commit changed 2 characters):

QuazarOmega,

For real, or when you should make the first and second commit.
Or worse, when you’re too focused and start making a ton of changes, then you realize you haven’t committed anything. Discovering I can stage ranges has made me fall for this way too many times, because I think I’ll easily just go back and extract one atomic change at a time later (spoiler: it won’t be easy ( ; ´ Д `))

pkill,

as soon as you realize you can’t easily contain your commit message within a 50-character conventional message (or slightly more if you wand to be more specific about the scope)

onlinepersona, in 4 billion if statements

I honestly thought this was going to be about AI 😅

CC BY-NC-SA 4.0

MxM111,
@MxM111@kbin.social avatar

No, this is about NS. Natural Stupidity.

qwertychomp,

Wait, what’s with the creative commons license? Are you licensing your comments?

candyman337, in Password requirements are getting out of hand

“Password length requirements: 6 inches”

Guy tries to make an account

“Password requirements not met”

“Bro I swear that’s 6 inches 😢”

dingleberry,

Can’t login when it’s cold.

mattd,

My password was in the pool!

merc, in 4 billion if statements

I like this bit at the end:

As a side note, the program is amazingly performant. For small numbers the results are instantaneous and for the large number close to the 2^32 limit the result is still returned in around 10 seconds.

caellian,

Really makes you question your sanity when optimizing jumps in code without benchmarks.

merc,

For a long time I’ve been of the opinion that you should only ever optimize for the next sucker colleague who might need to read and edit your code. If you ever optimize for speed, it needs to be done with massive benchmarking / profiling support to ensure that the changes you make are worth it. This is especially true with modern compilers / interpreters that try to use clever techniques to optimize your code either on the fly, or before making the executable.

Klear, (edited )

The first rule of optimization: Don’t do it
The second rule of optimization: Don’t do it yet (experts only)

Ephera,

I’m absolutely on-board …in application code.

I do feel like it’s good, though, when libraries optimize. Ideally, they don’t have much else to do than one thing really well anyways.

And with how many libraries modern applications pull in, you do eventually notice whether you’re in the Python ecosystem, where most libraries don’t care, or in the Rust ecosystem, where many libraries definitely overdo it. Because well, they also kind of don’t overdo it, since as a user of the library, you don’t see any of it, except the culmulative performance benefits.

merc,

Libraries are also written and maintained by humans.

It’s fine to optimize if you can truly justify it, but that’s going to be even harder in libraries that are going to be used on multiple different architectures, etc.

blusterydayve26, (edited )

I’m still mad he didn’t use the size of the number to tell the system which block to read first. I feel like that would be a great use of division or maybe modulus?

merc,

I just like how he used “% 2” in the Python code he used to generate the C++ code.

Ephera, in 4 billion if statements

Now we just need to someone to package it and upload it to NPM.

ArtVandelay,
@ArtVandelay@lemmy.world avatar

What’s another 40 gb of node modules anyway

akash_rawal, in no.. just no

I actually like this. This would allow reuse of all the infrastructure we have around XML. No more SQL injection and dealing with query parameters? Sign me up!

CanadaPlus,

Assuming it’s built well. As someone else pointed out, it doesn’t look quite right here.

utopianfiat,

So you mean like parameterized queries, which exist?

akash_rawal,

Better than parameterized queries. Yes, we have stuff like query(“INSERT INTO table(status, name) VALUES ($1, $2);”).bind(ent.status).bind(ent.name).execute…, but that’s kind of awful isn’t it? With XML queries, we could use any of the XML libraries we have to create and manipulate XML queries without risking ‘XML injection’. e.g we could convert ordinary structs/classes into column values automatically without having to use any ORM.

docAvid, (edited )

I mean, that’s just a bad library interface. With a halfway decent interface, you can do something like


<span style="color:#323232;">query('insert into foo (status, name) values (:status, :name)', ent)
</span>

No orm required. With tagged templates in JS, you can do


<span style="color:#323232;">q`insert into foo (status, name) values (${ent.status}, ${ent.name})`
</span>

Even wrap it in a function with destructuring to get rid of ent:


<span style="color:#323232;">const addFoo = (q, {status, name}) =>
</span><span style="color:#323232;">    q`insert into foo (status, name) values (${status}, ${name})`
</span>

Typescript can add type safety on top of that, of course. And there’s the option to prepare a query once and execute it multiple times.

Honestly, the idea of manipulating XML queries, if you mean anything more fancy than the equivalent of parameter injection, sounds over-complicated, but I’d love to see a more concrete example of what you mean by that.

akash_rawal, (edited )

I was thinking along the lines of

https://lemmy.world/pictrs/image/4ef7f59c-88c7-4cfa-8dd5-91c71d8ad801.jpeg

Plenty of libraries can build the XML using structs/classes. e.g. with serde:


<span style="font-style:italic;color:#969896;">//Data type for row
</span><span style="color:#323232;">#[derive(serde::Serialize)]
</span><span style="font-weight:bold;color:#a71d5d;">pub struct </span><span style="color:#323232;">Foo {
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">pub </span><span style="color:#323232;">status: String,
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">pub </span><span style="color:#323232;">name: String,
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">//Example row
</span><span style="font-weight:bold;color:#a71d5d;">let</span><span style="color:#323232;"> ent </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> Foo {
</span><span style="color:#323232;">    status: </span><span style="color:#183691;">"paid"</span><span style="color:#323232;">.</span><span style="color:#62a35c;">into</span><span style="color:#323232;">(),
</span><span style="color:#323232;">    name: </span><span style="color:#183691;">"bob"</span><span style="color:#323232;">.</span><span style="color:#62a35c;">into</span><span style="color:#323232;">(),
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">//Example execution
</span><span style="color:#323232;">sqlx::query(</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;serde_xml_rs::to_string(</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;InsertStmt{
</span><span style="color:#323232;">	table: </span><span style="color:#183691;">"foo"</span><span style="color:#323232;">.</span><span style="color:#62a35c;">into</span><span style="color:#323232;">(),
</span><span style="color:#323232;">	value: </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;ent,
</span><span style="color:#323232;">})</span><span style="font-weight:bold;color:#a71d5d;">?</span><span style="color:#323232;">).</span><span style="color:#62a35c;">execute</span><span style="color:#323232;">(</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;conn)</span><span style="font-weight:bold;color:#a71d5d;">?</span><span style="color:#323232;">;
</span>

Or with jackson-dataformat-xml:


<span style="font-style:italic;color:#969896;">//Data type for row
</span><span style="font-weight:bold;color:#a71d5d;">public class </span><span style="color:#0086b3;">Foo </span><span style="color:#323232;">{
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">public</span><span style="color:#323232;"> string status;
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">public</span><span style="color:#323232;"> string name;
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">//Example row
</span><span style="color:#0086b3;">Foo</span><span style="color:#323232;"> ent </span><span style="font-weight:bold;color:#a71d5d;">= new </span><span style="color:#0086b3;">Foo</span><span style="color:#323232;">();
</span><span style="color:#323232;">foo.status </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#183691;">"paid"</span><span style="color:#323232;">;
</span><span style="color:#323232;">foo.value </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#183691;">"bob"</span><span style="color:#323232;">;
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">//Example execution
</span><span style="color:#0086b3;">XmlMapper</span><span style="color:#323232;"> xmlMapper </span><span style="font-weight:bold;color:#a71d5d;">= new </span><span style="color:#0086b3;">XmlMapper</span><span style="color:#323232;">();
</span><span style="color:#0086b3;">String</span><span style="color:#323232;"> xml </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> xmlMapper.writeValueAsString(</span><span style="font-weight:bold;color:#a71d5d;">new </span><span style="color:#0086b3;">InsertStmt</span><span style="color:#323232;">(</span><span style="color:#183691;">"foo"</span><span style="color:#323232;">, ent));
</span><span style="font-weight:bold;color:#a71d5d;">try </span><span style="color:#323232;">(</span><span style="color:#0086b3;">Statement</span><span style="color:#323232;"> stmt </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> conn.createStatement()) {
</span><span style="color:#323232;">    stmt.executeUpdate(xml)
</span><span style="color:#323232;">}
</span>

I don’t do JS (yet) but maybe JSX could also do similar things with XML queries.

No more matching $1, $2, … (or ? for mysql) with individual columns, I could dump entire structs/objects into a query and it would work.

Hotzilla, in 4 billion if statements

Could be easily made 50% space saving by only iffin all odds and return even on else. Maybe one if before to handle overflow to avoid wrong even if over the last if.

Deebster,
@Deebster@programming.dev avatar

Well yeah, if you allow cheating!

bjorney, (edited )

Yeah but then ALL even numbers would be slow to compute because you would have to chain through every odd before you know that 2 is even.

Depends on the expected distribution of input values

coloredgrayscale,

Heuristic: keep it until 512, afterwards powers of 2, and numbers like 1000, 2000,…, 10000, 20000,… (regex: [0-9]000+)

themusicman, in 4 billion if statements

It’s not a trade off between dev time, execution time and memory as the author claims. It’s materially worse for all 3

rainerloeten, (edited )
@rainerloeten@lemmy.world avatar

I think he was being sarcastic, playing with words. Meaning, that you trade in time, runtime and memory and get nothing in return :D so a pretty bad trade haha.

Of course it’s worse, I mean, that was the point of this blogpost, wasn’t it? :p It’s just a (long) joke.

themusicman,

On reread, you’re totally right. Went right over my head

Kolanaki, in Good luck web devs
@Kolanaki@yiffit.net avatar

How many minor operating systems support it? 🤔

backhdlp,
@backhdlp@lemmy.blahaj.zone avatar

I’m assuming most that can run Xorg.

jdaxe,

Correct

jol,

There’s ReactOS and BSD off the top of my head.

Voyajer,
@Voyajer@lemmy.world avatar

Haiku counts

atocci, (edited )

I think ToaruOS does? I remember reading something about it but haven’t managed to install it yet to verify.

Edit: found it

gravitas_deficiency, in no.. just no

I want to hate this. I really do. But the problem is… I think I like it.

lorty,
@lorty@lemmygrad.ml avatar

This needs a bit of work but it could be interesting

naonintendois,

But how do I know if the WHERE clause is AND or OR?

gravitas_deficiency, (edited )

Fair. The constraint nodes should probably exist under an And or Or node.

akash_rawal,

We can say default is and and add an Or node for or. Similar to SoP notation, you only write +.

victorz,

How about an or boolean attribute.

xX_fnord_Xx, in Good luck web devs

Finally, Peewees Playhouse has found open source representation.

catbaba,

Jambi is GNU

henfredemars, in Debugging

You’re sure that there was a crime? You’re fortunate that your bug is consistently reproducible.

Gormadt,
@Gormadt@lemmy.blahaj.zone avatar

My “favorite” is when following the steps to reproduce a specific bug you get an entirely different bug then what was reported

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programmer_humor@programming.dev
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20975616 bytes) in /var/www/kbin/kbin/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php on line 171

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4210688 bytes) in /var/www/kbin/kbin/vendor/symfony/error-handler/Resources/views/logs.html.php on line 38