Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Lumpy posted:

What is "estimating"? Is that when you first hear the arbitrary deadline imposed on you?
I was saying you are correct in estimating "don't think learning typescript and getting the tooling all set up will fit in [three days]".
Because even just getting the tooling all set up correctly, if you can do typescript just fine already, will likely take you more than three days, unless you already happen to use an overcomplicated set of tooling that can trivially flip over from javascript to typescript.

Adbot
ADBOT LOVES YOU

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Is there a lazy way in Javascript to avoid making this mistake I always make when doing adventofcode sort of things?
code:
let input = `butt=4, rear end=3
butt=7, rear end=7`;
for (const line of input.split(/\n/)) {
  let [discard, butt, rear end] = line.match(/butt=(\d+), rear end=(\d+)/);
  console.log(butt+rear end);
}
Where I want the output to be 7, 14 but of course the output is 43, 77. I know how to fix it once I realize I've done it, but is there some sort of thing I could use more like sscanf where I extract numbers from a string in the form of numbers in the first place rather than having to remember to call parseInt on them all after the match?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

You can put a unary + operator in front of the variable to force it to cast to a number even if string, which is just one character to type as opposed to parseInt, so maybe then you'll remember to?
That is a handy thing I didn't know, thanks. I don't think it will work for this purpose though, because you can't do [+a, +b, +c] = numbersExtractedFromAString;

But it will at least make it less annoying and verbose when I notice and do the retroactive correction.

vvvv Yeah, I got it, but that's where it's too late for me to cultivate a habit of doing it - converting at use-time rather than at capture-time.

roomforthetuna fucked around with this message at 08:00 on Dec 16, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

Yeah it's hard coming out of line.match. I doubt there's a way to use the + operator on the call itself that respects the destructuring of the returned object.
I suppose I could just not destructure it at first hit, like
code:
let m = line.match(/stuff/);
let [x, y, z] = [+m[1], +m[2], +m[3]];
Which I wouldn't have wanted to do with parseInt, but with the unary + might be short enough to work.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

That seems MUCH better and more explicit to the reader. First line is about strings, second line is about numbers.
Well, it's adventofcode sort of things I'm doing (in a real programming context I wouldn't mind just using parseInt) so there is no reader.

Learning about the unary plus already paid off today though, I'm pretty sure it saved me enough time to gain a position, and having talked about it also kept me from making the "forgetting to turn strings into numbers" mistake again, so thanks!

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Argh I have spent two days trying to make this poo poo work. How do you set up two typescript modules, one of which depends on the other, without going through a full publish and import rigmarole every time you change the dependency one?

The internet is all "use yarn link or npm link but it won't work lol" which is true, it doesn't work.

Today I found yarn workspaces that sounded good but the instructions for that are like "here's how you create a workspace, ha ha that is all, good luck actually using it". So I've got a yarn workspace that as expected includes symlinks to my local modules and installs of all the other dependencies, but now what, how do I actually build a thing here, the tsconfig.json file is now inside a symlink inside node_modules which presumably is not how you're supposed to use that, and I have no loving idea how this is going to eventually tie in with webpack. Is my main project's package.json supposed to *be* the workspace-defining one?

Also something about typescript project references and "tsc --build" maybe? Maybe it can perform the build inside the node_modules folder?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Aha, I found a sort-of answer to my question, which is that evidently webpack is doing something a bit different from the way package.json people think you'll be building stuff. As such, having
code:
"baseUrl": "path/to/your/dependencies"
in your tsconfig.json allows a webpack set up with ts-loader to do its thing without any package.json in the dependencies nor any intermediate js files being generated nor any references to the dependencies in the node_modules of the topmost package.

The one remaining difficulty I was having was that for some reason a 'package' in that path that was only exporting one function (a debug-log function that's basically just a wrapper around console.log whose purpose is to be stripped out in a production build) was simultaneously "not found" and capable of whining about syntax errors or the function from it not being found if I changed its name. I just moved that file arbitrarily into one of the other packages and from there it worked fine. Mysterious. So obviously I'm not super comfortable with what I have going on, but it does build now, and doesn't require any extra command-line operations to pick up on dependencies being updated, so the setup finally meets pretty much all the criteria I had.

Relatedly, has anyone here done anything with WebRTC? That's nearly as much of a clusterfuck to get going as webpack+typescript+npm. I got that working too, finally, and all it requires is like 14 messages through two server connections in order to establish one peer-to-peer connection.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Tip posted:

That's disheartening, I'm about to start work on some new features that I planned to use WebRTC for... Maybe I'll just do it the old fashioned way instead.

I just spent forever fighting with the Web Audio API, which is a giant piece of poo poo with all kinds of weird limitations placed on it for no reason. Like, yeah, you can encode mp3s, but only in real time. And yeah, the api has most of the standard audio effects and filters, but it doesn't specify their implementation, so you get different results in every browser.
If it's not important to you to go peer-to-peer, I strongly recommend not even thinking about WebRTC. Websockets are pretty good and not at all a giant pain in the rear end, comparatively. You basically have to implement your own peer-to-peer connection through your server to communicate how to form a peer-to-peer connection not through your server, so for probably 95% of use-cases you might as well just carry on communicating through your server since you already set that up.

Nolgthorn posted:

Are you sure you're designing something that needs webpack+typescript+npm? I imagine you are hitting yourself in the foot with a hammer because of all that tooling. WebRTC is just one of those things, the spec is designed by committee and so even though it's P2P you need like 2-5 intermediary or ancillary servers that do whatever.
Well no, it doesn't need all the things, but webpack doesn't work without some amount of npm, and typescript for a large project would suck without some sort of package wrapper, and webpack seems to be the only one that supports dynamic module loading which I want because my project is intended to be extensible, and I don't want it to have to load everything before anything works.

I have reduced it to not using npm to control my own libraries - I was going to open-source my WebRTC wrapping library and its server sibling, but npm being a pain in the rear end has persuaded me not to (which is funny because I got the feeling npm is to some extent designed as "you open-source or you pay!" but somehow it became so annoying that I'm not even going to open-source the thing I was intending to.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Nolgthorn posted:

Not to tell you how to do it but I'd just compile separate js files as needed, then use the `async` html tag. Bingo bongo and it's done. The only thing typescript's compiler is bizarrely still missing is iife, so I use something lightweight like buble when I need it if I'm using typescript.

Webpack is like trying to land a rocket on mars, when all you really want is a little fin that's on the rocket. It has like 8 billion dependencies, it's a bloody mess.
That sounds like the "just do it myself with loving makefiles" option that I considered a while back. But I don't want to end up with as many js files as I have ts files - one of the things webpack does nicely is it takes my 20-or-whatever typescript files and it turns them into three or four somewhat-minified js files (and map files!) in the most appropriate configuration for dynamic loading.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dominoes posted:

What method do you recommend for causing a long calculation to not block the main thread?
A method I used that's easy and cheap is something like this:
code:
function moment() {
	return new Promise((f) => {
		setTimeout(() => f(true), 0);
	});
}
async function yourLongFunction() {
	// [at some not-too-common occasion]
	await moment();
}
If you await moment() too often it will take thousands of times longer to run your function though. You can either call it less often, or put something in there so it returns Promise.resolve() if it was called recently, and the setTimeout promise otherwise - even then you still don't want to call it super often, but like 10000 times a second with that version is fine.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dominoes posted:

This appears to work as a quick in-place fix! Much easier than I'd assumed. Of note, the call to await moment_() must be at the top of the func; eg the slow code below.
You have to call await moment() repeatedly from the slow function to have it work. Waiting for a setTimeout of duration zero to resolve essentially means "yield for one UI cycle now". There is no way to actually multithread javascript other than introducing webworkers, which are relatively high effort.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

MrMoo posted:

Sounds like you are holding it wrong. The spec has changed a lot which is the most annoying. I have a video wall setup to render a 16K video with it.
As far as I can tell you need:
1. one peer sends an RTCSessionDescriptionInit to the other via the server.
2. the other peer applies that one and generates a response one, sends that RTCSessionDescriptionInit to the first peer.
3. both peers now start generating IceCandidates, which it seems to be recommended you communicate as soon as they are generated. In my test case, each side generated 6 RTCIceCandidateInit objects, which makes it 14 messages through the server total. I figure you probably could clump all the IceCandidates together into one message each way, since more are generated even if you don't send them, but I'm not sure if that would be better or worse (also not sure if the list is communicated via the callback with some kind of a null-terminator at the end or what, none of the examples were clear on why it's valid for an IceCandidateEvent to have its 'candidate' property unset.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

I have a key-value collection of arrays, and each array is expected to be the same length.

Example test data:

code:
const arrays = { a: Array(10), b: Array(10), c: Array(10) };
What is the most concise way to retrieve that length?

Object.values( arrays )[0].length seems kind of excessive since it has to touch all the stored arrays when i just need one.
If you're targeting an ES6 target and you're also in control of your key-value collection, you could make the collection as a Map rather than a {} object, which would then allow you to access it as an iterator rather than duplicating the keys into an array, which I believe would allow you to look at just the first element.

But if your data is going to/from JSON or something then you might be just front-loading the extra pass to do that.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Siddhartha Glutamate posted:

The biggest problem I have is that the variable game.playerMoves, which right now logs the color of one of the four options the player has, will at first show the correct selection, but then it will double the selection. So if on the first turn the player clicks on the blue X the log will read "blue" then on the second turn if the player clicks red it will log "blue, red, red" and each additional time through it will log the click multiple times instead of once.
The linked codepen doesn't include the same code you posted, and doesn't even have responsive buttons.

I think the problem you have (that you described, not from the CodePen) is that you're calling numCrunch before each turn, and you never remove the eventListeners from your buttons, so on the first turn they each have one eventListener, on the second turn they have two, etc.
You could either remove the eventListeners and add them again after each move (which would be good if you want buttons to be nonresponsive while noises are playing or something), or just leave them active until the game is over and not add them repeatedly.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

roomforthetuna posted:

Aha, I found a sort-of answer to my question, which is that evidently webpack is doing something a bit different from the way package.json people think you'll be building stuff. As such, having
code:
"baseUrl": "path/to/your/dependencies"
in your tsconfig.json allows a webpack set up with ts-loader to do its thing without any package.json in the dependencies nor any intermediate js files being generated nor any references to the dependencies in the node_modules of the topmost package.
A followup to this tale of woe, I debugged the tsloader package with some log statements to try to figure out why some packages from my baseUrl would load and others would not.
I didn't ever quite resolve why some packages would would, but I found the reason for the failure is that "baseUrl": "C:/herp/derp" in tsconfig.json gets transformed by the loader module into "C:/herp/derp/C:/herp/derp" by going through code that says if (!path.Absolute(yourPath)) then append it to current working directory.
If you instead (or additionally) put it in webpack.config like
code:
  resolve: {
    plugins: [new TsConfigPathsPlugin({configFile: 'tsconfig.json', baseUrl: 'C:/herp/derp'})],
  },
then it gets passed through through path.resolve instead of path.isAbsolute, which doesn't do the self-appending thing, so everything works (at a slightly annoying cost of having to specify baseUrl in two places instead of one.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dominoes posted:

Hey dudes. What's the best way to refresh data from a server every 30 seconds or so? So points to using setInterval, but the answers are mainly from 2010, so not sure if its' still the best way. Eg call a fetch functino from setInterval. Don't think I need websockets for this.
setInterval is still alright, though there's a small risk of weirdness if a request takes over 30 seconds for some reason. Do you actually want a request every 30 seconds, or do you want, say, 30 seconds after the previous request completing? I generally prefer the latter, so I do it with a setTimeout to send the request again at the end of the response-handler (and error-handler) rather than setInterval, which protects against the small risk of ending up with two or more requests in flight at once.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Rahu posted:

My question is, is there some way I can add an object to res.locals (or the request or response objects in general) and keep the typescript compiler aware of its type? I've defined an interface named LoginStatus that describes the properties of this object.
I think the closest thing to what you're asking for is you could make an interface that 'extends' the request/response interface/class with an override of the locals type.
Just tried this in the typescript playground and it seems to work:
code:
interface LoginStatus {
    whatever: string;
}
interface LoginStatusResponse extends Response {
    locals: { loginStatus: LoginStatus };
}

type LoginResponseHandler = (res: Response) => void;

const x: LoginResponseHandler = (res: LoginStatusResponse) => {
    // Do whatever
}
Edit: (Not sure if the Response type that exists in the playground matches the type you're working with, but I tried extending over an existing member of a different interface or class type and it was accepted just fine.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dominoes posted:

Another one: Is there an elegant way to dedupe an array of tuples?
Not super elegant, but something like
code:
function tupleEquals(a, b) {return a[0]===b[0] && a[1]===b[1];}
a = a.filter((v1, i) => a.findIndex((v2) => tupleEquals(v1, v2)) !== i);
This is O(n^2) - you could bring that down if your data is large by first sorting by tuple-contents and then doing filter comparisons only between adjacent elements, but much like this it'll still be DIY sort functions and comparisons, and will still suck.

And if you want to make it generic you're going to be doing something even worse like transforming your tuples into JSON strings, then you can put *those* into a set to remove duplicates and then de-JSON the elements of the set afterwards.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Roadie posted:

Fun fact: It's also dependent on the specific interaction of map and JSON.stringify/parse, so if you swap those for other functions weird poo poo might happen.
What? In what way? It's the normal expected way map and the JSON functions work, they're not doing anything specific to the pairing are they?

Like yeah this behavior is specific to a reversible mapping to/from a unique identifier, but if you switched the JSON functions for any other reversible to/from unique value serializer/deserializer the outcome would be the same.

I mean yeah, if you switched them out for other functions like ... parseInt and console.log then weird poo poo would happen, but it's always the case that if you swap out a function for a function that does something different then something different will happen. How is this case special such that you're remarking on it?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Roadie posted:

Array.map supplies three arguments to its callback, not one. If you use a whateverParsing function that isn't as quick to dump non-matching args as the JSON.x ones are, it'll use those to do...... something.
The first argument is the useful one though. You don't need a function that discards anything, you just need a function that doesn't take additional arguments.

But you're right that it's dependent on the specific implementation, in that it's technically undefined behavior to use JSON.stringify this way, since its second parameter is documented as a function or an array of filters or null or unset, and array.map will feed it an index which is a number which is none of those things, and its third parameter is documented as as a string or number or null, and array.map will feed it an array in that position.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Kraus posted:

But, the leaderboards on that site claim that it can be done in as little as 33 characters. Does anyone have any idea how?
Recursion is pretty much always shorter than iteration.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Doom Mathematic posted:

JavaScript code:
a=0;b=1;while(b<1e6){print(b);c=a+b;a=b;b=c}
(44 chars)
(NB. that gets the beginning slightly wrong)
And then save some chars with the recursion effect:
JavaScript code:
f=(a,b)=>(print(a),b<1e6&&f(b,a+b));f(0,1)
(42 chars)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Dumb Lowtax posted:

I feel like if you've got a good background on pointers and references from a C++ background or a quality CS intro class you just don't ever have that misunderstanding
Which is why you make a handy deep-copy function, because you know this is going to happen and you want to avoid it.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Nolgthorn posted:

What pitfalls
Stack overflow from circular references is a good one.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

FSMC posted:

I have been writing code like that but I don't understand how it works. If things can run out of order am I just getting lucky or are simple statements be guaranteed to run in order?
The only things that can run 'out of order' are promises and events, and they can never interrupt code that's currently running.
Javascript is hard single-threaded.
If you want it to handle events or promises in the middle of your function you have to essentially make the rest of your function be triggered by an event or promise that will resolve later than the one you want to wait for.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

FSMC posted:

If I write an AI in a single function that takes an hour to run, as long as I haven't used promises or timers will js just wait for it to finish before moving on with the rest of the code?
Yes (and the browser tab won't update and you can't interact with the page and consequently most browsers will eventually say "this javascript might be broken, do you want to wait for it to finish or kill it")

Edit: and "single function" isn't important, you could have it be 90 functions across multiple modules, if the function that was called doesn't return and doesn't yield to a timer or await a promise in some way the outcome is the same even if it called a bunch of other functions repeatedly or whatever.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

FSMC posted:

I've managed to lose this post a few times so I'll keep this brief. The code I had problems with was something like this. I just wanted it to get the state of one device then move onto the next. But what actually happened was the the loop the second get in the loop would start before the first one had a response. So there were errors as the first in the loop was waiting for a response and the second trying to ask a device for its state. In the end I had to get rid of loops made a messy function which called itself with the index of the next device to get.

code:
async function getState(keys) {
        keys.forEach(async key => {
          await this.get(key).then(result => console.log(result));
        });
}
Aha, your problem is not actually with async/await/promises, it's forEach!
To get the result you expected, you could do
code:
async function getState(keys) {
  for (const key of keys) {
    const result = await this.get(key);
    console.log(result);
  }
}
What's happening with forEach is it calls a function for each element, and there's no 'await' in that call, so even though each function itself waits for the result, since they're async functions and the caller (forEach) isn't awaiting the outcome, the caller can carry on immediately.

(Also, there's rarely any point in mixing await and 'then' syntax in the same function.)

(Also, debug-stepping through forEach sucks balls.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Strong Sauce posted:

there is a slight difference between the for control flow statement and foreach array iterator.

a for loop goes through the first iteration, gets held up by the await, waits for the await to resolve before moving to the next iteration of the for loop

a forEach array iterator, you pass a function. after you define a function that it immediately invokes for every single element in the array at the same time.

when you do, "[1,2,3].forEach(i=>console.log(i))" you are actually executing 3 functions all at once. since nothing is asynchronous in this case, it will output just fine. 1, 2, 3. but if each call is asynchronous, then you will get values back as soon as they resolve.
This is misleading, nothing is ever executed "all at once" or "at the same time" in Javascript.

The forEach is effectively the same as a for loop that calls the provided function for each entry. The difference is that if that's an async function, when it hits an await or similar, it returns flow back to its caller (in the form of returning an unresolved promise under the hood). If the caller then doesn't 'await' the result of that promise, which forEach does not, then the caller moves on to whatever is next in its sequence, in this case the next subject of the forEach.

Given a regular non-async function though, a forEach executes the entries sequentially like any other for loop.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Strong Sauce posted:

where whatever code in those functions are determined by the response time of the IO being called. then yes, i agree, and that is essentially what i said.
Yeah, wasn't trying to explain to you as if you didn't get it, just trying to minimize the confusion your phrasing would cause for someone who was already having trouble understanding the ordering of things.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

necrotic posted:

Using firebase you can just toss your site up on a static host (including firebase, which has a static site hosting option). The mongo approach requires running your own backend for the mongo access.
The downside of static hosted firebase is that getting the permissions stuff right (so users can't just poke around in your database however they want) is fairly tricky, or at least it was when I last tried. (I see there's built-in login and user-level authentication stuff now so maybe it's better, it's been a while since I tried it.)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

IIRC, the Sources UI will present the option to jump to the implementation of a symbol when you're stepping through in debug because then it actually knows for sure what the implementation is. Otherwise, due to the nature of the language, it'd be an educated guess no better or not much better than a text search.
I'd much rather have the educated guess than no functionality. "Not much better than a text search" actually is much better than a text search if you're dealing with multiple files, because text searches across multiple files are inconvenient as gently caress and require you to type what you're searching for and then they come up with every instance of that string, vs. eg. pressing F3 on a thing and going to the one instance that's a function definition not a call, or being presented with a list of likely candidates. If VS Code can do it, so could another tool!

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Doom Mathematic posted:

You're doing i.html, which will return undefined because i is a number, which has no html property. I think you want something like linktoList[i], which is a DOM element you can do more work with.
Also you're doing for (i=0; i < ltl; i++) when you mean for (i=0; i < ltl.length; i++).

Edit: oh wait, ltl *is* the length, and then you don't have the list. Don't do that.
Edit2: oh wait, you do have the list, but then you re-perform the search to construct the list in order to make ltl contain its length. Madness. linktoList.length, man!

roomforthetuna fucked around with this message at 00:02 on Mar 27, 2019

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Generally codegolf sites give you something shorter than document.write to work with, so there's probably like 10 characters saved there in the number you're citing unless it was explicitly specified this many characters with document.write.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I don't use Parcel, but I back the recommendation anyway, because unless you want to do some wacky combination like typescript with dynamic module loading it's way less of a headache than the alternatives.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Nolgthorn posted:

If you've got some digital clocks on your page. You've got javascript that loops though all the ".clock" elements and starts updating them every second that passes, but you want them in different timezones you might set "data-timezone" attributes so that in your javascript you just have to look at the element's "data.timezone".

It's super useful if your entire page isn't js.
Yeah, it's good where you want to communicate something from your raw html content to your javascript. If you find yourself populating data attributes from your javascript you're probably doing something daft.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

The Dark Wind posted:

Edit: So is it standard practice that if you have awaited something in a child of a child of a child, it's pretty much async/awaits up the tree?
Except if you at any point in the chain don't care to wait for the result, like you might have...
code:
onButtonClick() { doSomeStuff(); }
doSomeStuff() { getValueFromServerIntoSomeBox(); }
async getValueFromServerIntoSomeBox() { someBox.contents = await getValueFromServer(); }
async getValueFromServer() { return await doSomeAjaxShit(); }
etc.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Newf posted:

"Do not block the main thread" is a thing in javascript for the web. I assume it's also the case for an express app that handles client requests.

Is this as simple as making sure that all of the stuff I do is via methods marked async?

Can anyone describe or link to an auditing process to ensure that code is non-blocking? Are there tools (in the TS ecosystem, maybe?) that can lint for it?
No, async doesn't prevent you from blocking, an infinite loop in an async function will still stop everything.

It's actually as simple as making sure all of the stuff you do doesn't have an infinite or long-running loop (I guess this is why I think it was Airbnb has a style guide that forbids loop style flow control entirely, only allowing forEach style iterator loops). There are basically no blocking functions in the ecosystem, so the only way to block is to not come out of a loop.

There is no linting for this, because it's basically the Halting problem. But you can do like Airbnb and forbid all flow control if you're a nutcase.

Edit: unit testing with 100% coverage is fairly good for ensuring no infinite loops too, but there are ways you could trick it.

Edit2: vvvv I didn't want to address actual threads in JS, because the question was fundamentally misled enough that it clearly wasn't about advanced concepts like WebWorkers.

roomforthetuna fucked around with this message at 23:08 on May 4, 2019

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
This seems like a good place for this rant, even though it's not directly JS/TS - today I learned that Dart is a stupid language for chumps.

Because it's touted as type-safe, but unlike Typescript literally anything can be null whenever it feels like it. List of strings? More like null or list of null-or-strings! Hope you like handling all possible null cases in all your functions every loving time!

I'd been using it for several weeks at work under the impression that it was like Typescript where a type means what you say, and today a reviewer suggested I might want to include tests for what my function does if my list of objects contains nulls and I like was "wait, what the gently caress, my list can contain nulls?" I thought the reviewer was mistaken, but no, the language really is that poo poo. And I mean it's not "can contain nulls" like you can coerce Typescript into doing, it's just flat out happy to accept ["foo", null, "bar"] as a parameter of type List<String>.

I realize Javascript is happy to mix nulls and things too, but that's 100% dynamic typing, Javascript doesn't claim to be type safe so it's expected. Dart is mostly even more type safe oriented than Typescript, but then it goes and pulls this loving nonsense, what the gently caress. Don't use Dart.

(Even Javascript can do compile-time null-rejection if you use the Closure compiler and ask for non-nullable types!)

roomforthetuna fucked around with this message at 02:19 on May 8, 2019

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Volguus posted:

I used dart in a flutter project recently and it wasnt that bad. I was just learning flutter and dart so the code i wrote was very much not pretty, but for the most part things worked as expected.
Yeah, I was okay with it, "comparable to Typescript" was my conclusion, until someone suggested I should handle null parameters that I didn't account for. That made me realize it was possible (and easy) to deliver nulls by accident, which adjusts my conclusion to "significantly worse than Typescript".

It's barely better than Javascript at that point, in that as you say "for the most part things work as expected". Allowing surprise nulls is just a loving travesty though for a typed language.

I'm using it for Flutter too, which is quite a hefty paradigm shift from any other UI stuff I've done, gives it a bit of a steep learning curve for doing anything advanced, but I don't mind that. I wouldn't even really mind the null thing if it wasn't just so obnoxious. Unexpected nulls are barely even a thing in C++ for the last 8 years, who would make a new language and let them be a thing? It'd also be okay for small solo projects where I can be confident I won't pass myself null values, but for team things you've gotta handle any edge cases your functions make possible that some jackwagon might do, which means basically every function has to begin with "assert(arg!= null); assert(!listArg.contains(null));" which is stupid as gently caress. (Or you have to make a crapload of use of the "?." and "??" operators, which would be wonderful operators for using on parameters that you've described as null-or-a-type.)

In other newish languages that completely gently caress up handling of nulls: Go (click Run, then compare main() against the output, the rest of the stuff is just there as a sort of vaguely-realistic setup for that lovely behavior.)

Adbot
ADBOT LOVES YOU

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

Dart was kind of a mashup of Java and JS, so I'm not sure why you'd expect it to be any better about non-null types than those languages. Rust and Kotlin are the two up-and-coming languages I can think of that even have them, with C# getting them soonish. Hell, maybe Java got them in 9, but I'm not up on new Java features.

Not that I'm defending Dart here - just kinda baffled that anyone is expecting it to be better about null handling than its ancestors.
Typescript is basically Javascript, and is better about null handling than its ancestor.
Java has an @Nullable annotation (a variety of them even!) so linters can tell you to gently caress off with your possibly-nulls. The fact that so many versions of that exist really should have informed a language-maker that there was a desire for this feature.

I wouldn't have particularly expected Dart to be decent in isolation, I expected it to be decent because a team had chosen to use it, and why would you choose to use a language that's worse than Typescript or C++, in a company where lots of people already know Typescript and C++?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply