Programming

2 Likes

Refactoring deck chairs on the Titanic

1 Like

I think it’s notoriously impossible:

https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/

You could have your function be async and decide at runtime whether or not val needs to be awaited, but that’s not really very nice. Or you could just make all your testFns async. But basically if testFn might return a Promise, then you’re going to be stuck with binarySearch returning a Promise too.

1 Like

Yeah this is why I avoid async in JS. Its very hard to wrap your head around anything complicated when you are facing “well is this is a sync or async function and what happens when its called, exactly, and what happens next, exactly” over and over. Just use promises or callbacks and it makes sense and follows a normal flow of logic and you can see what blocks or what doesn’t pretty easily.

1 Like

Eh you know whats funny is I’ve been writing full stack JS for years and years and have heard that argument a bunch and I’m like wtf are you guys doing right? Like how is there “endless nested callbacks” in anything you write?

If its front end you make an async request there’s just 1 callback situation unless your back end is written terribly. On the back end you receive a request and make another async request to a DB and respond back with that. If you need more than that Promise.all works fine. I don’t really get it. I know the nested }) stuff isn’t a lot of fun but prettier and vscode handles that stuff OK but again just don’t see why this is some massive problem. :man_shrugging:

async/await is just promises under the covers. I love using it. The only time you have to go to raw promises is making a bunch of async calls in parallel.

But yeah to use await in a function, that function has to be async.

Interestingly, it’s theoretically possible to do this in Python, because async Python is built on generators, which you can poll from synchronous code. So you could just poll your future in a loop until it completes and returns the value. But in JS, the only way to access the result of a Promise is through a handler, and all handlers run through the microtask queue, and the JS engine won’t touch the microtask queue until it runs the current script to termination. So it’s flatly impossible.

In Node, you can use util.inspect to get at the hidden internals of the Promise to see the value (source), so it’s theoretically possible to see the value of a Promise that resolves synchronously in subsequent synchronous code. But unless the authors of the async function you’re calling were just being difficult, presumably the Promise you’re interested in doesn’t resolve synchronously, so the resolution of the Promise you’re interested in will also occur in a microtask, which means that the Promise can never resolve until the current synchronous script terminates, even if you spin long enough for the underlying API call/syscall/other work to finish.

But if your async function looked like this:

function getAPIResult(query) {
    return new Promise((resolve, reject) => {
        if (this.cache.has(query)) {
            resolve(this.cache.get(query))
        } else {
            this.callAPI(query).then(result => resolve(result)).catch(error => reject(error))
        }
    })
}

and the query you pass in is found in the cache, then the getAPIResult function will return a resolve Promise (the Promise body itself runs synchronously when the Promise is constructed). In that scenario, you could mess around with util.inspect to extract the result from the returned Promise in synchronous code. But, uh, that’s probably not the solution to your problem.

In some theoretical sense, all JS code is “supposed” to be async. Synchronous code is supposed to be the high-priority stuff that has to preempt everything else when it’s invoked, like UI event handlers. In effect, when you declare a sync function in JS, you’re really declaring a “do not disturb for any reason” function, which logically means the function can’t have a dependency on a lower-priority task, because it’s declared to be the top priority, so the lower-priority task will always defer to it. You want to tell JS that it’s OK to pause execution of your function until testFn resolves, but that’s a syntax error, because you’ve also declared your function as unpausable.

What async code is really doing, at least in JS, is allowing you to declare a dependency graph for different chunks of your code. It’s interesting to imagine an alternative version of the language where the default is async execution, with each line of code being implicitly then-chained to the previous line, unless you explicitly make them a synchronous block. I mean, that’s basically what async/await is, but since it’s not the default, it’s natural to start writing a program in “never defer” mode and then realize halfway through that that was a mistake, because your code (either inherently or through APIs) has nonlinear dependencies that can’t be represented in never-defer code.

2 Likes

Found out that our HR application uses COBOL to calculate people’s salary, OT pay, etc

1 Like

This is actually horrifyingly common, especially in government. COBOL has built-in fixed-width decimal math, which is (arguably) better suited for financial representations, because it doesn’t lose accuracy on many operations. (Michael Bolton’s plot in Office Space presumably takes advantage of some kind of floating-point bug in this vein.) FORTRAN still exists for similar reasons:

https://medium.com/the-technical-archaeologist/is-cobol-holding-you-hostage-with-math-5498c0eb428b

dude you are getting married. you can either buy and set it all up now, or you first gotta run these ideas by the wife later.

1 Like

fun fact, the oculus apps from the link upthread wasn’t available during the outage. lol.

image


4 Likes

My boss wants to turn our little donor portal site into a mobile app. Because it’s cool to say we have a mobile app that does the exact same thing as our mobile website.

But we’re a team of about 5 and everyone is always stretched thin, so running the existing site in a progressive web app seems like the only way to go.

Does anyone know how that’s done these days? Just fire up XCode and Android Studio and build an app with an embedded webview? Or is there some other cross-platform way to do a PWA?

What isn’t it still react native?

I looked at what it takes to convert a react app to react native and it seemed like a lot.

Sounds like maybe Cordova is the way to go.

As others have mentioned there’s no quick way to convert react to react-native.

A possible alternative if you want your react app to run on a mobile device without rewriting your codebase is to use Cordova. For fun I ported a react-web app into a mobile app using Cordova in just a few minutes. There are some drawbacks to this method, but the benefit is that you can have a working mobile app in very little time.

You cannot just use your whole code into the react native application. First and foremost, you have to follow the react native architecture and then develop your UI using react native components. Introduction · React Native You’ll get most of the help here.

There is another option also, you can just create a new react-native project and use webview in it and display your whole website there. https://facebook.github.io/react-native/docs/webview.html

WebViews and React-native are two completely separate concepts. Either you want to go with the former (than you can actually use your application without much hassle), or with the latter. In that case, you could probably re-use some of the business logic, however most of the rendering would have to be rewritten.

React native is learn once, write anywhere , not learn once, write once :)

Yeah I mean all of your views (html) will need some work and you’ll have to maintain 2 things but thats just a given, still. There’s a bunch more of these (flutter?) but I don’t think there’s anything else you can do.

Right. I was just wondering if there’s one that everyone is using now. These mobile app platforms seem to come and go so fast.

i don’t work on this part of our code, but just had to check

08:33 $ git grep "void\*\*\*"
runtime.h:    void** bufferPtr = *reinterpret_cast<void***>(&m_Data[m_Size * m_tupleSize + m_sortSize]);
1 Like

https://blog.binaryage.com/totalfinder-totalspaces-future/

This really sucks. I use the shit out of TotalFinder. I didn’t even realize that I can only Cmd-X/Cmd-V to cut and paste files because of TotalFinder.

I’m glad I got a new Mac before the M1s. But I’m going to have to upgrade from Big Sur one of these days. Ugh.

Apple, because fuck you that’s why.

Lol. My project has a database pool of about 250 “nodes”. Today after 4 years of working here finally learned the secret sauce. Those nodes have a total of 10 terabytes. Of RAM.