|
"the peeps behind C are too old to care about"
sigh... that's racist. lol. Not really, but I'm trying to fix something that works in the real world. I already have some thoughts about your posts.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: sigh... that's racist. lol Touché, buddy.
Jeremy Falcon
|
|
|
|
|
"I'm sure C is ran by grandpas still using an outhouse."
Okay Mr. Falcon, you're getting edgy here and somewhat triggered me. I would point out that there is beaucoup code out there happily running all written in C. The good news is that we - us grandpas and great grandpas - have a STABLE compiler. It's only worked for decades. But lets take a look at your code examples. Now, I don't know anything about "zig" other than it's another open source compiler to continue to confuse crap... so fair disclaimer.
"pub fn main() void {"
Great, so for decades the suggestion has been to make your variable names readable in whatever language is native to you. Looks like zig has reduced public to pub and function to fn. Not a good start.
"const res = c.write(2, "Hello C from Zig!", 17);"
does not impress me. Why? I'm supposing c.write assigns the output to res.
- Is res a dnamically allocated variable? String? Buffer of x bytes? Again, I don't know zig, but I have further issues.
- What does the 2 do?
- 17. Hmm, why not let the compiler handle the null terminated string? If I change the string, boom, the # is wrong.
Fights on Everything I just posted is meant in technical respect.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: The good news is that we - us grandpas and great grandpas - have a STABLE compiler. I should say, C is and will always be my favorite language. It's served me well over the years and will always have a special place in my heart. I promise I'm not one of these zealot hater types.
But, ya know... I will joke about it.
charlieg wrote: Great, so for decades the suggestion has been to make your variable names readable in whatever language is native to you. Looks like zig has reduced public to pub and function to fn. Not a good start. I'm a realist, so there are things in Zig I'm not crazy about. IMO they should've made the syntax a bit more C-like to be C 2.0. But, the good outweighs the bad. So, I overlook stuff like fn instead of function .
I totally agree with the point that we should be moving away from too many abbreviations though, 100%.
charlieg wrote: Is res a dnamically allocated variable? String? Buffer of x bytes? Again, I don't know zig, but I have further issues. It's the same as using that C function in C. No different. Zig just allows you use that C function so you don't have to abandon decades of code on the C side. So, write would return the number of bytes.
charlieg wrote: - 17. Hmm, why not let the compiler handle the null terminated string? If I change the string, boom, the # is wrong. Actually, the compiler does handle that. I was just being lazy and writing a simple example.
charlieg wrote: Fights on Everything I just posted is meant in technical respect. Fair enough. Just know I love C. I do wish it evolved a bit more in the past 50 years though. Adding new features doesn't mean you have to break compatibility.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: Forgive me because I'm becoming a wordle post.
Could be worse, could be a CCC post.
|
|
|
|
|
So, here I am... n00bing it up in a new language and getting my learn on. Wut wut. And I come accross a feature that's postponed for now as the language is still young... async routines. Ok, I get it. It's new to the party. I can still do multi-threading, so not end of the world should I need to block something that would otherwise be non-blocking.
Buuuuuuuttt, ran across a few posts online with the typical "I never used it so I hate it" mantra. And it got me wondering, do people really hate the concept of asynchronous routines? Seems to me the only people that hate it just don't know it. Like at its core (using JavaScript as a reference) all it does is reduce complexity with what would otherwise be non-blocking code. Fail to see why that's so bad.
Using pseudocode...
function bruh() {
const response = fetch('/stuff');
console.log(response);
}
async function bro() {
const response = await fetch('/stuff');
console.log(response);
}
Like, why is that so bad? I bet these people would freak out over the concept of generators. I just don't see why people would hate this. Am I not alone with this thought?
Jeremy Falcon
|
|
|
|
|
Not a fan of async methods myself (in C#). I had never experienced them before, but I recently had to figure how to call them synchronously in order to use some third-party software which insisted -- for no reason that I could tell.
|
|
|
|
|
Unfortunately, I mean you know how it is, when a new buzzword is created so many peeps jump on the bandwagon as a excuse to use just to sound cool. So, I could totally see it being unnecessarily used. But, I don't see that as a problem with the simplified syntax. I see is as a people problem not really bothering to learn crap.
There are things that inherently should be asynchronous. File IO, Network IO, etc. Your application should never lock up if there's a problem or it's slow, etc. However, it's also nice to be able to simply say in simple syntax wait for this crap because because because. It's really nothing more fancy than that.
Maybe there should be two hotlines... one for macro abuse and another for async/await abuse.
Jeremy Falcon
|
|
|
|
|
Certainly. And maybe using threads can be confusing to some.
But I spin up threads whenever I need to. And not when I don't.
|
|
|
|
|
Touché
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: should be asynchronous. File IO, Network IO,
Uh, say what? I don't see it.
|
|
|
|
|
If you have a potentially long running process (because of a timeout on failure, etc.) your application shouldn't lock up because of it. Too many instances of trying to cancel a command line app or use a GUI that just locks while it's off just chillin.
Jeremy Falcon
|
|
|
|
|
Maybe you are thinking only of GUI applications?
I write mostly command-line utilities and they take and long as they take. I tend to have them log something every ten seconds or so so you know it's still at it and not just gone down to the pub.
In a WinForms application, I might spin up a thread, and use a ProgressBar or something if possible.
|
|
|
|
|
Same applies on the console. If you cannot cancel a long running process then that's no bueno. If data integrity is a concern then making operations atomic should be a consideration. It's never a good idea to look up a computer more than a second or so.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: never a good idea to look up a computer more than a second or so.
Bullpuckey.
Ctrl-C kills most console utilities anyway. Not a problem.
|
|
|
|
|
Gotta disagree there, it sends a signal like SIGINT which can totally be ignored if a program hangs. I've had way more than one app just tell me "whatever bro" after smashing Ctrl+C over and over.
Jeremy Falcon
|
|
|
|
|
Never, not once. But then again, I don't write utilities which hang.
And Ctrl-Z on OpenVMS.
|
|
|
|
|
I dunno what apps you've used, but clearly we've used different ones. Either way, looks like we're gonna disagree on whether or not some things should be non-blocking. I still still think non-blocking is cool and the way to go, if possible.
Oh the upside, it's Saturday and there's ice cream to be had.
Jeremy Falcon
|
|
|
|
|
It certainly has its uses, but that doesn't mean that it should be forced on everyone all the time.
Use it when it makes sense, same with everything.
Something to bear in mind is whether or not you have anything else to do while you wait. If not, you're still just waiting.
Or, in a real language, I can spin up a thread and do other things in my process, zing bang Bob's your mascot.
|
|
|
|
|
PIEBALDconsult wrote: Something to bear in mind is whether or not you have anything else to do while you wait. If not, you're still just waiting. I'm trying to end this discussion because it's going nowhere man. I've already mentioned there is always something to do, like respond to user input or signals. It's clear you have zero desire to agree with me, so not sure why we be dragging this out man. If you need to read a 1 byte file that's guaranteed to be small, cool... assuming it's local and not network attached. I'm referring to long operations. Not sure why this needs to be dragged out.
Jeremy Falcon
|
|
|
|
|
Again, I write mostly back-end stuff, there's no user input or anything. A long-running task is still going to take a while. Querying a database for some data and writing it to a file of some sort could take minutes or longer no matter what. And I can use a different process to do something else at the same time.
Or spin up multiple threads in one process to write multiple files, no big deal. That's my bread and butter.
Other languages can support other needs.
|
|
|
|
|
A user can be a script. Clearly, you just don't wanna agree man.
But hey... ice cream.
Jeremy Falcon
|
|
|
|
|
Whenever I have to use the fetch API in JavaScript, I need to use an asynchronous function because fetch is inherently asynchronous and returns a promise. I sometimes create a promise object within synchronous functions, and that seems to work OK as well. I suppose that if I used promises the way they're meant to be used, they'd be great. Sometimes promises don't return a response and are rejected. I should probably bother to address that in my code but I just don't. The only times I need to use promises, and asynchronous functions with the await keyword are when I need to retrieve XML, JSON, or HTTP data. The XMLHttpRequest runs just fine synchronously but it's always a good idea to use an asynchronous function and the await keyword anyway. Considering that JavaScript runs as a single thread, asynchronicity is nice to have. So, no, wouldn't say you're alone in that.
|
|
|
|
|
Totally agree man. It's JS we're talking about, so I'm about to yap a lot...
In JavaScript async/await is especially important. JavaScript by it's very nature is meant to be non-blocking. Without getting too much into the history of it for one post, I'll just say that's a strength of JavaScript. But, it does come with some gotchas, as you mentioned. Here's the 30 second history of it dealing with non-blocking code in JS.
In the beginning, there were callbacks. The Lord spoketh, thy non-blocking code doesn't return. Thou shalt use callbacks. Now callbacks were great, but they don't chain. And things got convoluted real quick. JS will always be non-blocking, so then now what?
Promises! They came about to deliver us from callback craziness. They chained... all was well... until folks realized promised also go complicated too. You could have like 10 promises all with nested variables (closures helped with this a bit), but it got messy if a coder didn't modularize crap nicely.
Now, the reason I said all that was because, all async/wait is in JS is syntax sugar for promises. You can in fact return a promise and call it with await. It'll work. Even though it's just syntax sugar, it still cleans things up and makes variable scoping with return values, etc. muuuuuuch less cumbersome.
Oh side note, throwing an exception in an async function is no different than rejecting a promise. Just cleaner syntax.
Jeremy Falcon
modified 22-Aug-24 9:10am.
|
|
|
|
|
this. was trying to recall why I disliked asynchronous, and something with JavaScript, but seeing op post and then quick lookup "var response = await fetch(url)", that seems so easy.
Thinking I thought you had to do callback functions. So yeah, you can do both, oh neat.
But that whole callback thing urks me. It's more how the flow of data I see in my head
function
get this data
now with the data do X thing
but callback
function
get this data
end function
some other function
now do thing with this data
its that separation of functions which my internal mapping does not like
|
|
|
|
|