programmer_humor

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

mlg, in no.. just no
@mlg@lemmy.world avatar

“HTTP and the Web is a totally reliable and easy to use internet protocol”

mvirts, in no.. just no

Remember kids, JSX is just function calls. It can’t hurt you.

Thcdenton,

Oh it can and it did.

normalexit, in no.. just no

This idea is bad and whoever came up with it should feel bad.

III,

It never ceases to amaze me how far idiots will go to avoid learning the most simple things. SQL isn’t hard, people’s difficulty with it says a lot more about them than it does SQL.

emptyother,

People think in different ways. What might seem logical to you might look alien to another. I know SQL well enough to optimize queries, but I find it a lot easier to think about and write queries as LINQ methods. A lot more cleaner and logical to my brain.

MonkderZweite,

Neither is sending form data to the server without any JS. It’s more robust too. Yet almost no form on the web works without JS.

Sanchokan, (edited ) in The Holy Trinity of JavaScript

A few years back I came to the conclusion that the holy trinity in Christianity are three levels of abstraction: the son => God walks on earth and tangible, the father => God in heaven untangible but still reachable by speech, holy spirit => God in who knows where.

Then I thought that as a way of imparting the thought that any level of abstraction of the universe would also be inhabitated by God, those which we can sense, and those where our senses can't reach. The idea that omniprescense is not only limited to our dimension.

I'm not sure if that is the original meaning but is a way of seeing it that I can relate to, since I've always been akeen to a more abstract idea of God, and not so much to a figure that praises itself of thought, which is a human attribute.

yannic,
CanadaPlus,

As far as I can tell, the doctrine of the trinity served political rather than logical purposes back when it was put in writing in late antiquity, and since then it’s just been the doctrine. If you want to believe, you just have to believe and not think about it too hard, like the video says.

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.

kamen, in The Holy Trinity of JavaScript

Lots of silliness indeed, yet I can’t remember the last time I had to use a non-strict comparison.

CanadaPlus,

Yes, it’s been established that you can still use JavaScript, and it will only backfire sometimes, even though it’s a bad language. And yet, people try to use it where it’s not even required.

dylanTheDeveloper, in no.. just no
@dylanTheDeveloper@lemmy.world avatar

Omg that’s terrible! Link?

NovaPrime, in 4 billion if statements
@NovaPrime@lemmy.ml avatar

Andreas is a maniac

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

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+)

ThrowawayPermanente, in 4 billion if statements

Let’s be real though, everything is IF statements all the way down

Th4tGuyII,
@Th4tGuyII@kbin.social avatar

There's not a single thing in this universe that cannot be accomplished with enough IF statements... as long as you've got infinite time to wait

waz, (edited )

…you mean IF you’ve got infinite time to wait?

Klear,

…you mean if you’ve got IFinite time to wait?

firecat,

The problem with if is the answer comes from user. There’s no mathematical reason or scientific explanation, only programmer who thinks the answer should include the subject.

Th4tGuyII,
@Th4tGuyII@kbin.social avatar

True...

But even on a more metaphorical level, every single thing that has or will happen in this universe, down to even the smallest quantum fluctuations could be encapsulated into IF statements as long as you had enough of them.

idunnololz,
@idunnololz@lemmy.world avatar

What if there was an unintentional infinite loop in your code. You could be waiting for infinite time only to learn the code had a bug. D:

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.

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?

GreatBlueHeron, in 4 billion if statements

I’m not a good reader - I skim most articles and often miss most of the meaning. I read, and enjoyed, every word of that!

librecat,

Thanks, I totally would’ve skipped it without this comment.

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.

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