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
marshalljim
Mar 6, 2013

yospos

fuf posted:

Uhhh an incredibly obscure platform / language that's only used by Universities called SITS ("Strategic Information Technology Systems"). It's a weird niche I fell into by accident that means a secure job but development that is straight out of the 90s.

I have a fair bit of web dev experience though so I'm definitely not starting from scratch with JS or anything. I'm firmly in 'intermediate' territory, just with a strong sense that I'm missing fundamentals and need to update my skills.

Frontendmentor.io, Free Code Camp, whatever. All the well known ones are fine for getting you coding and learning, and then you can get more focused and fill in the holes you discovered. It's not like there's some magic bullet beyond putting in the hours.

Adbot
ADBOT LOVES YOU

fuf
Sep 12, 2004

haha

marshalljim posted:

It's not like there's some magic bullet beyond putting in the hours.

Yeah but those hours can be spent more or less efficiently. There's a huge difference in the quality of pedagogical material. With software dev courses especially there's a lot of pretty bad teachers out there. Good teaching is a real skill and unfortunately it doesn't often coincide with good software engineering skill.

fuf fucked around with this message at 09:10 on Dec 21, 2022

Armauk
Jun 23, 2021


Interesting!

If you are planning to dive more into JavaScript/React, I recommend learning TypeScript. Many jobs and projects pretty much require using it. And, for good reason: It helps catch errors you would have otherwise missed in sprawling vanilla JS codebases. There are many resources and IDE tools that will help lower the barrier of entry.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It also speeds up development dramatically on teams. Because even if I don't know what your function does I can be confident it takes certain types and returns certain types.

Thank God

Deadite
Aug 30, 2003

A fat guy, a watermelon, and a stack of magazines?
Family.
Is there a quick way to compare two arrays of objects where neither the array or the objects are in the same order, but have the same contents?

For example
code:
var array1 = [{“key1”:”a”,”key2”:”b”},{“key3”:”c”,”key4”:”d”}];
var array2 = [{“key4”:”d”,”key3”:”c”},{“key2”:”b”,”key1”:”a”}];
Both arrays contain the same objects just in different order, but I can’t find a way to compare when they’re like this. I can find a solution if the objects with the same key/value pairs had the same index in both arrays, but I’m not sure what to do if they have different positions within the arrays.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
For arbitrary objects that you know absolutely nothing about there's no "quick" way. Ultimately what you need to do is check the first object in the first array against every object in the second array to see if anything matches, and likewise for the second, third etc. objects in the first array - and that's not going to be a quick process for large arrays.

If you know a little bit about the objects, though, then it can get a lot faster and easier. If you can convert each item to a unique primitive object (such as a string), in such a way that the same object always converts to the same string and different objects always convert to different strings, then you can add all of these things to a Set and quickly determine whether the Set for each array is the same.

If you can't quite convert your objects to unique primitives, but you can convert them in such a way that the same object always gets the same primitive, and different objects mostly get different primitives, you can use a Map from that primitive to an array of corresponding objects. That way when fully testing equality, you only need to check against the handful of objects with the same primitive instead of every single object in the original array.

There might be some sort of data structures and collections library available that makes this easier. If there is, you might decide that you don't need arrays here in the first place (especially if order doesn't matter), and you just want to keep these objects in some sort of "HashSet" to begin with.

Doktor Avalanche
Dec 30, 2008

Deadite posted:

Is there a quick way to compare two arrays of objects where neither the array or the objects are in the same order, but have the same contents?

For example
code:
var array1 = [{“key1”:”a”,”key2”:”b”},{“key3”:”c”,”key4”:”d”}];
var array2 = [{“key4”:”d”,”key3”:”c”},{“key2”:”b”,”key1”:”a”}];
Both arrays contain the same objects just in different order, but I can’t find a way to compare when they’re like this. I can find a solution if the objects with the same key/value pairs had the same index in both arrays, but I’m not sure what to do if they have different positions within the arrays.

lodash?

AlphaKeny1
Feb 17, 2006

Jabor posted:

For arbitrary objects that you know absolutely nothing about there's no "quick" way. Ultimately what you need to do is check the first object in the first array against every object in the second array to see if anything matches, and likewise for the second, third etc. objects in the first array - and that's not going to be a quick process for large arrays.

If I understand correctly, yeah I think this is correct. It would be better to take care of this when storing your data but if you can't and if your only option is to deal with two arrays of different objects then it might help to transform it using a data structure and then make comparisons after.

For example, iterate through the first array and create a hash map/set. Then iterate through the second array and compare it to the map using hasOwnProperty() or something. It will be "fast" in that it will be O(n) time but require additional space to create your map. There might be other optimization techniques as well.

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!

Deadite posted:

Is there a quick way to compare two arrays of objects where neither the array or the objects are in the same order, but have the same contents?
Other people's suggestions of "put it in a map" are good if you can do that *and* you want to do this sort of operation more than once on the same data (like keep it in a map or set the whole time and don't use an array at all).

If you just want a one-off comparison then you get there more efficiently by doing a sort on the arrays (doesn't matter what you use as the sort criteria so long as they're consistent), then you can compare item by item along the index. Running quicksorts with a comparison function will be faster than all those map insertions with a hashing function, or stringification.

Edit: algorithm-wise, quicksort is typically O(n log n), but worst case is O(n^2), vs hashmap insertions would be O(n), but in practice the hashmap adds a bunch of allocating and stuff, and hashing is in general not quite as fast as comparing fields. Given that potential worst-case performance of quicksort, you *might* be better off literally just doing the nested loop doing comparisons from the original arrays, but it can be a bit of an error minefield if, e.g. there can be duplicate values. That option also has the advantage that it's non-destructive (if you want to sort non-destructively then you also add two copies). Also depending on the context maybe you don't even give a gently caress about performance, if you're just comparing like arrays of <50 things in a context that's not framerate-related.

roomforthetuna fucked around with this message at 02:04 on Dec 27, 2022

smackfu
Jun 7, 2004

The prettier formatter must be interesting code. You would think it would always produce the same output for semantically same code but it clearly tries to preserve existing linebreaks. Not a question, just a musing.

CarrKnight
May 24, 2013
I am a pretty experienced Java programmer. I need to work on a year-long project on something browser based. I am thinking JS or Typescript but quite frankly the problem is that I have never dealt with browsers before (as in, I barely understand what HTML and CSS files do).

Basically I am looking for a 3-6month learning strategy/book/course that gets me into coding JS/Typescript and understand how to deploy it.
The problem I am running in into however is that all the learning material I find is really targeting very first time learners ("what is a for loop?" kind of topics).

Is there anything on teaching people who already code how to do it in JS/Typescript?

Sab669
Sep 24, 2009

I'd recommend just looking up like "Intro To X" or "Crash Course On X" where X is the framework/libraries you'll be using (React / Angular or whatever) or environments it'll be running in rather than just like "Javascript how do I X" where X is some common thing that virtually every language can do but just does differently.

go play outside Skyler
Nov 7, 2005


Might not be a popular opinion but as someone who's done a lot of everything web, a lot of embedded, a lot of Java, Kotlin and Swift, I'll say this: in 2022 it doesn't really matter if you barely know how HTML and CSS work anymore. Nowadays there's so much poo poo going on between the code you write and what's delivered to the browser, you'll be using a build system that handles all that stuff for you.

Unless you're supposed to be the one initiating the project and building it from scratch, I'd just start learning React, Vue or Angular + TypeScript and worry about the details later. React in my opinion is the best, least opinionated framework, but the most important is to learn whatever your company plans to be using.

Because you're not going to be the one starting the project from scratch, are you? ...???

CarrKnight
May 24, 2013
Right, thanks for comments.

To be fair, I am not going to build any very complicated web-app; rather what I really need to produce is a "one-page" app where users play a bit with some sliders for inputs, the "javascript application" I need to write crunch those numbers into some output and then plots some neat graphs.
It's basically a "run stat analysis in browser" kind of app with no connection to either data-bases or any other server. The need for JS (or typescript or whatever) is just because we want a user to run analysis without having to download an excel spreadsheet or, god forbid, a desktop program.

Given this use-case, do you guys still think the right approach is to start with React?

go play outside Skyler
Nov 7, 2005


CarrKnight posted:

Right, thanks for comments.

To be fair, I am not going to build any very complicated web-app; rather what I really need to produce is a "one-page" app where users play a bit with some sliders for inputs, the "javascript application" I need to write crunch those numbers into some output and then plots some neat graphs.
It's basically a "run stat analysis in browser" kind of app with no connection to either data-bases or any other server. The need for JS (or typescript or whatever) is just because we want a user to run analysis without having to download an excel spreadsheet or, god forbid, a desktop program.

Given this use-case, do you guys still think the right approach is to start with React?

100%, but start with something that does all the boilerplate for you like create-react-app. Enjoy the ease of development of doing npm start during development and learn about how to build a release version of your app with web pack and upload all that poo poo to a server.

fsif
Jul 18, 2003

go play outside Skyler posted:

Might not be a popular opinion but as someone who's done a lot of everything web, a lot of embedded, a lot of Java, Kotlin and Swift, I'll say this: in 2022 it doesn't really matter if you barely know how HTML and CSS work anymore.

I'm curious about your rationale here because this strikes me as a baffling take. Are you only talking about creating private apps that look like garbage and don't care about accessibility?

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!

fsif posted:

I'm curious about your rationale here because this strikes me as a baffling take. Are you only talking about creating private apps that look like garbage and don't care about accessibility?
I think the gist was more "you pick some wrapper-framework that makes it look like Google's latest hideous style poo poo then you don't need to know any of that any more."

(From my perspective, the opposite, I'd rather know javascript, html and css, and not know how to use those loving frameworks, and make a page that looks how I want, behaves how I want, and doesn't have 2MB of extraneous libraries embedded to not actually do anything.)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Basically instead of building a site by putting in <p>s and <div>s and <a>s and styling them appropriately with CSS, you use a component library that lets you just put in entire widgets and components. Like instead of making a sidebar by having a react component that emits some <divs>, and corresponding CSS that makes them float:left or however you want to implement it, you just use someone else's react component for a sidebar.

You don't care about how the HTML and CSS behind the sidebar works, you just take the component as-is. It was the component author's job to care about that stuff, so you don't have to.

Obviously this works a lot better with mature component libraries that actually provide good abstractions. If it's a leaky abstraction where you're constantly having to gently caress around with the HTML and CSS for the component to make it work right within your app, then you should chuck out that whole library and get one that's actually fit-for-purpose.

fsif
Jul 18, 2003

Yeah that can work for a hobby project or maybe an internal company tool (which tbf I assume the OP is building) but it won't get you too far past that.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

fsif posted:

Yeah that can work for a hobby project or maybe an internal company tool (which tbf I assume the OP is building) but it won't get you too far past that.

It's actually the opposite - the larger the project, the more you need to know the component library being used, and the less you need to care about minutiae of HTML and CSS.

Once you get large teams of people all working on the same project, you literally have to componentize - if you want to be at all productive, you can't have people loving around with CSS and inadvertently changing parts that aren't the thing they're directly working on. Once you have a componentized UI, only the developers actually creating the components need to care about HTML and CSS - everyone else can use the components as-is and can put all their effort into caring about how those components are composed together and wired up to the data you're wanting to display in them.

fsif
Jul 18, 2003

Jabor posted:

It's actually the opposite - the larger the project, the more you need to know the component library being used, and the less you need to care about minutiae of HTML and CSS.

Once you get large teams of people all working on the same project, you literally have to componentize - if you want to be at all productive, you can't have people loving around with CSS and inadvertently changing parts that aren't the thing they're directly working on. Once you have a componentized UI, only the developers actually creating the components need to care about HTML and CSS - everyone else can use the components as-is and can put all their effort into caring about how those components are composed together and wired up to the data you're wanting to display in them.

That's just… absolutely not correct. Even enterprise companies with coherently developed design systems (of which there aren't many!) can't rely on a set of several dozen components that are never updated and only ever used in extremely prescribed patterns. You're going to reach edge cases, new business logic, updated brand guidelines, entirely new UI, etc that will dictate that you will, at some point, need to create or edit new HTML or CSS.

And I don't even know how you'd begin to understand the nuances of said component library without a strong foundation in HTML/CSS in the first place!

camoseven
Dec 30, 2005

RODOLPHONE RINGIN'

Jabor posted:

It's actually the opposite - the larger the project, the more you need to know the component library being used, and the less you need to care about minutiae of HTML and CSS.

Once you get large teams of people all working on the same project, you literally have to componentize - if you want to be at all productive, you can't have people loving around with CSS and inadvertently changing parts that aren't the thing they're directly working on. Once you have a componentized UI, only the developers actually creating the components need to care about HTML and CSS - everyone else can use the components as-is and can put all their effort into caring about how those components are composed together and wired up to the data you're wanting to display in them.

This is certainly how upper management imagines that it should work. But it sure does not!

Data Graham
Dec 28, 2009

📈📊🍪😋



fsif posted:

That's just… absolutely not correct. Even enterprise companies with coherently developed design systems (of which there aren't many!) can't rely on a set of several dozen components that are never updated and only ever used in extremely prescribed patterns. You're going to reach edge cases, new business logic, updated brand guidelines, entirely new UI, etc that will dictate that you will, at some point, need to create or edit new HTML or CSS.

And I don't even know how you'd begin to understand the nuances of said component library without a strong foundation in HTML/CSS in the first place!

Once the project is done and we've completed all our requirements we'll have a perfectly maintainable system!

... what's that?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

fsif posted:

That's just… absolutely not correct. Even enterprise companies with coherently developed design systems (of which there aren't many!) can't rely on a set of several dozen components that are never updated and only ever used in extremely prescribed patterns. You're going to reach edge cases, new business logic, updated brand guidelines, entirely new UI, etc that will dictate that you will, at some point, need to create or edit new HTML or CSS.

And I don't even know how you'd begin to understand the nuances of said component library without a strong foundation in HTML/CSS in the first place!

I am literally talking from experience here.

Yes, someone needs to understand HTML and CSS to write and update the component libraries. It does not need to be you, the developer doing a higher-level task like adding a "track package" button to gmail or putting the view count widget next to the other counters in the twitter UI.

fsif
Jul 18, 2003

Jabor posted:

I am literally talking from experience here.

Yes, someone needs to understand HTML and CSS to write and update the component libraries. It does not need to be you, the developer doing a higher-level task like adding a "track package" button to gmail or putting the view count widget next to the other counters in the twitter UI.

If your literal experience has you still talking about floats then I have to assume said literal experience is fairly limited and/or completely out of date.

I can promise you the developer tasked with deploying template changes to Gmail knows HTML and CSS.

fsif fucked around with this message at 17:15 on Dec 30, 2022

minato
Jun 7, 2004

cutty cain't hang, say 7-up.
Taco Defender

CarrKnight posted:

Given this use-case, do you guys still think the right approach is to start with React?
I think React might be a minefield for you. When it's working as intended, it feels like magic: your code will be clear and concise, and you can easily find useful components to slot into your app. But as soon as you butt heads with something tricky, you will need a good understanding of JS fundamentals in order to push forward; copy/pasting from StackOverflow will only get you so far. React topics like controlled vs uncontrolled components & hooks are probably not easy for webdev novices who are already overwhelmed with the many other Things You Have To Know just to get to Hello World.

Ditto with Typescript.

That said, it may still be worth going through the create-react-app setup steps, simply because that will also walk you through the not-fun aspects of setting up a webdev environment for the first time; webpack, nodejs, babel, yarn/npm, deciding on a directory structure, etc. Take the Create React App tutorial as far as getting to their Hello World, and then you can ditch the React library and just use the tools & framework to create a regular web app.

For CSS, just use Bootstrap. It's super popular so there's lots of support and examples. You don't need to learn much CSS to get up and running.

You don't need to know much HTML at all. Put simply, just know what the DOM is, what elements are, and that elements have attributes. Then 95% of the HTML you wright is going to be DIV, P, SPAN, and IMG elements. Use MDN as your primary JS/DOM reference docs, they are famously excellent.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
I feel like people starting afresh might be better off with Next rather than create-react-app since the dev environment is so much more pleasant.

camoseven
Dec 30, 2005

RODOLPHONE RINGIN'
Honestly a SPA that doesn't hook up to any databases or APIs and just makes pretty graphs based on sliders is dead simple if you know what you're doing, and you should probably hire a contractor to do it in a week instead of spending time trying to figure it out yourself

fuf
Sep 12, 2004

haha
So in React I think you're supposed to pass down functions from the parent to the child component so that it can be called by the child:

JavaScript code:
function DeleteTag(tag){
...
}

<TagList DeleteTag={DeleteTag}/>

This is fine but is it still the best way when your component hierarchy gets pretty large? Like:

JavaScript code:
// parent.js
function DeleteTag(tag){
[...]
}

<TagList DeleteTag={DeleteTag}/>


// TagList.js
[...]
<SingleTag DeleteTag={DeleteTag}/>
[...]

// SingleTag.js
[...]
<DeleteButton DeleteTag={DeleteTag}/>
[...]
This gets pretty annoying, especially with TypeScript where you have to be super explicit about the Props being passed down to every component. It's a lot of work to pass down a function three or so levels just so that it can finally be called by <DeleteButton>.

Is there a way to just call DeleteTag() in parent.js from <DeleteButton> directly? Or is that somehow going against the whole React ethos?

Is this where I want a custom hook maybe? (I don't really know what they are)

fuf fucked around with this message at 13:49 on Jan 28, 2023

smackfu
Jun 7, 2004

Yes, that is a classic concern with React. “Prop drilling” is the common term if you want to Google. The solution has usually been to have some global state that your various level componentscan hook directly into. Redux was popular for a while, I think plain React context is the current choice?

Also don’t capitalize your functions unless they are components.

Edit: React docs link: https://beta.reactjs.org/learn/passing-data-deeply-with-context

smackfu fucked around with this message at 14:18 on Jan 28, 2023

fsif
Jul 18, 2003

Zustand has kind of become the de facto standard over context, I think.

fuf
Sep 12, 2004

haha

smackfu posted:

Yes, that is a classic concern with React. “Prop drilling” is the common term if you want to Google. The solution has usually been to have some global state that your various level componentscan hook directly into. Redux was popular for a while, I think plain React context is the current choice?

Also don’t capitalize your functions unless they are components.

Edit: React docs link: https://beta.reactjs.org/learn/passing-data-deeply-with-context

fsif posted:

Zustand has kind of become the de facto standard over context, I think.

Thanks, that's really helpful.

I've seen Redux mentioned a lot, and now I finally understand why it's useful.

I'm gonna try and rewrite things to use React Context.

It's annoying how you have to do things the wrong way first to figure out why the right way is the right way.

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!

fuf posted:

It's annoying how you have to do things the wrong way first to figure out why the right way is the right way.
There's an argument to be made that the "large context" way is less right, because e.g. if your components are things like "a button" then it makes sense to construct that as "a button with this label which, when clicked, does this action", i.e. passing all the variable elements in to it, rather than making a subclass "the save button" which then has to look at the containing context to find out how to perform its save action.

Especially in places where unit testing happens, "dependency injection" is preferred, because singleton context sucks for testing.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

fuf posted:

It's annoying how you have to do things the wrong way first to figure out why the right way is the right way.

Wait till you do things the right way and figure out why they're also wrong. All solutions point back to vanilla js, so then you do that and realize why React is probably the right way. It's a never ending circle.

go play outside Skyler
Nov 7, 2005


Nolgthorn posted:

Wait till you do things the right way and figure out why they're also wrong. All solutions point back to vanilla js, so then you do that and realize why React is probably the right way. It's a never ending circle.

Every time I try to start a project without react I end up with a million calls to document.createElement and sometimes I feel that all JS needs is a standardized simple template system.

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!

go play outside Skyler posted:

Every time I try to start a project without react I end up with a million calls to document.createElement and sometimes I feel that all JS needs is a standardized simple template system.
Isn't that what HTML is?
element.innerHTML='<div style="foo"><span id="bla">bla bla</span></div>';

MrMoo
Sep 14, 2000

More like JSX or Lit HTML, i.e. template literals with variable expansion and some level of macro support.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

go play outside Skyler posted:

Every time I try to start a project without react I end up with a million calls to document.createElement and sometimes I feel that all JS needs is a standardized simple template system.

But isn't that refreshing? I love it. It's like

JavaScript code:
function buildCatEle (name, age) {
    const ele = document.createElement('div');
    // etc...
    return ele;
}

const catEle = buildCatEle('Darby the Cat', 6);
catsEle.appendChild(catEle);
ah, peace and quiet.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
Now all you need is a state management system that knows which templates to re-render when your state changes and whoops, you have re-invented react

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!

Obfuscation posted:

Now all you need is a state management system that knows which templates to re-render when your state changes and whoops, you have re-invented react
Man, if they'd made react *without* the state management system then there might be a framework that I don't hate and wish death upon.

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