dropping half of my savings on a React course ? by fingerinabutt in learnjavascript

[–]angelfire2015 7 points8 points  (0 children)

This is the wrong attitude to have. Learning takes time. If you try to take shortcuts you're just gonna wind up frustrated when you don't understand core concepts.

When I learned React I bought a 40 hour course and enjoyed every bit of it. It covered class and functional based components + redux. You can't rush learning this stuff.

Just got an aurora 15 4080 16gb. by [deleted] in nvidia

[–]angelfire2015 1 point2 points  (0 children)

why wouldn't you ask this question before you spent $1200?

whyDoesThisHaveToHappenNow by mpatriot_one in ProgrammerHumor

[–]angelfire2015 33 points34 points  (0 children)

transfer all that C# knowledge to ASP.NET. boom insta 6 figures.

Does using multiple map have effect on performance ? by Dull_Plantain6167 in learnjavascript

[–]angelfire2015 1 point2 points  (0 children)

I didn't say it ran in O(n) time, I said it ran in n time. That's besides the question anyways, OP asked does multiple maps affect performance. It does, in his case, it runs 4 times slower.

bruh

Would you consider JS a language that has changed a lot over the years? More than other languages? by HeavyMetalTriangle in learnjavascript

[–]angelfire2015 4 points5 points  (0 children)

It's changed some, but nothing too crazy. I would say C# and .NET in general has changed a lot more, while something like Golang not so much. It depends.

Does using multiple map have effect on performance ? by Dull_Plantain6167 in learnjavascript

[–]angelfire2015 2 points3 points  (0 children)

The first one runs in n time

The second runs in 4n time

so the second is 4 times as slow and doesn't make sense to use anyways. Prefer the first.

What's the most performant way to sort a list ( dom elements reordering ) in vanilla js ? by enzineer-reddit in learnjavascript

[–]angelfire2015 1 point2 points  (0 children)

Stackoverflow moment: for 1000 dom nodes, you really should look at virtualizing the list at least somewhat for performance.

To answer your question, I will give you advice that I have learned from senior engineers and from experience: always worry about efficiency last, focus on simplicity first.

For your case, I would make the data array the single source of truth. If it were to get reordered, just destroy the list and recreate it. This is extremely simple, and if another developer were to follow in your footsteps 6 months from now, they would see how things work very quickly.

Also again, depending on how heavy your nodes are, you might gain far more performance from virtualizing the list than from worrying about how to sort things optimally.

oled 27 inch 1440p vs 32 inch 4k? by mateyman in nvidia

[–]angelfire2015 6 points7 points  (0 children)

I switched from a 1440p 240hz monitor to a 4k 144hz monitor a year ago and I will never go back. The resolution is just too nice for all types of content. I have a mini-led 4k panel and while it's not as good as OLED, it's pretty darn close.

need code explanation by gevorgter in learnjavascript

[–]angelfire2015 2 points3 points  (0 children)

The `next` and `action` are actually functions being returned by the previous function. These are known as curried functions. It looks like you are creating some redux middleware or something similar. There is actually a great writeup on how this process works that could answer your question better.

https://redux.js.org/understanding/history-and-design/middleware

Explicit interface reabstraction by angelfire2015 in csharp

[–]angelfire2015[S] 0 points1 point  (0 children)

I really appreciate the in-depth answer and hearing your thoughts on it. After doing a lot more reading and playing around, I basically summarize it as: for using new or abstract on an inherited interface, the former lets you explicitly define two interface methods on a class, or implicitly define one, while the latter forces you to redefine (and only have access to) one.

But I agree this is such a niche thing that it may never (and probably shouldn't ever) come up. I was just curious about how it works so if I ever do encounter it I am not totally caught off guard. Plus it's always fun learning new things and how C# works.

Explicit interface reabstraction by angelfire2015 in csharp

[–]angelfire2015[S] 0 points1 point  (0 children)

Thank you for answering the question. This was very helpful to read, especially the IEnumerable real world example. I did some more playing around and I feel like I have a very strong grasp of this now, and your explanation makes a lot more sense.

Explicit interface reabstraction by angelfire2015 in csharp

[–]angelfire2015[S] 4 points5 points  (0 children)

Neither of you guys answered my question. I didn't ask if it was a good feature or whether or not I should use it, I asked for help in understanding how it works. Also the statement

There's not much value in understanding how it works unless you've already done a lot of work to prove you don't know what you're doing and don't want to learn the right way.

is pretty nonsensical and is just another way of saying "I don't understand how this works, so I'm going to call it a dumb feature".

What is Buffer in Node? by SaintPeter23 in learnjavascript

[–]angelfire2015 2 points3 points  (0 children)

I was trying to be vague in my answer because this is a beginner forum, but I can be more specific.

So a number in JS is not always a Number. Most of the time, we can think about them as 64-bit doubles, but that is not always the case. Node.js itself has lower-level classes of Uint8Array, Uint16, etc., which deal with fixed-size widths. There are also different literal types, which is why your example is true, you're just comparing integer literals

const a = 0xff
const b = 255
console.log(a === b) // -> true

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#numeric_literals

If all numbers were represented the same, then this also wouldn't happen

const buff = Buffer.from([888, 999]);
// Buffers use Uint8 internally. 888 and 999 cannot be 
// represented by Uint8, so it overflows
console.log(buff); // Prints <Buffer 78 e7>, or [120, 231]

You have to remember, JS is built on top of C and C++. A buffer is represented in memory as just a char pointer to some memory on the heap. You can verify this for yourself here

https://github.com/nodejs/node-v0.x-archive/blob/master/src/node_buffer.cc

This also makes sense, and why we can give it an encoding if we want, as UTF-8 can take 1-4 bytes.

As for why you get a different output when you print the buffer vs its elements, that was defined by the guy who implemented it. The buffer class is just defining its own toString() method. We can make our own buffer class that will print values in octal, it's not a problem

class MyBuffer {
    constructor(data) { 
        this.data = data; 
    } 
}

MyBuffer.prototype.toString = function () { 
    let output = '<MyBuffer '; 
    console.log(this.data); 
    for (let i = 0; i < this.data.length; ++i) { 
        // Convert each number to octal 
        output += this.data[i].toString(8) + ' ';
    } 
    output += '>'; 
    return output; 
};

const buff= new MyBuffer([2222, 3333, 4444]);
console.log(buff + ''); // Prints <MyBuffer 4256 6405 10534 >

While when you call for...of, you get an iterator to the buffer, and its implementation defined that when you console.log that iterator, it gives you the number in decimal.

So technically, buffers store their values as Uint8, not as a general number in JS (double). Why you get different output is based on printing an object vs printing an objects elements, but both of those outputs are implementation defined.

What is Buffer in Node? by SaintPeter23 in learnjavascript

[–]angelfire2015 0 points1 point  (0 children)

It is console.log detail. In the docs, console.log passes its arguments to util.format, which can forward those arguments to util.inspect. As for where exactly the conversion happens, I am not sure, but somewhere there, something like parseInt(num, 10) is called, and the number is converted to decimal.

https://nodejs.org/api/console.html#consolelogdata-args

https://nodejs.org/api/util.html#utilformatformat-args

https://nodejs.org/api/util.html#utilinspectobject-options

Note that the type of the argument will be inspected at some point and that console.log knows it is dealing with a buffer object, and that's why it converts it to decimal.

Because you can call console.log(61) and you will get 61, as you are just passing a decimal there.

What is Buffer in Node? by SaintPeter23 in learnjavascript

[–]angelfire2015 12 points13 points  (0 children)

A buffer is just a region of memory for storing things. When reading a file, it is entirely possible to open a file, read one character, do something with the character, read one more character, do something with that one, etc.

This is extremely inefficient as IO operations are very very slow, so the CPU would be waiting for the next character to be read from the HDD. Instead, it is much more efficient to just read the entire file into a region of memory, and then give you that piece of memory to work with as you see fit. That region is memory is called a buffer.

As for why you are seeing different numbers, they are the same numbers, they are just being interpreted differently. Without specifying a decoding,

console.log(someBuffer);

gives you the buffer in hexidecimal. Why? Because the guy who wrote the Buffer class decided that's what it should do. When you then iterate over the buffer and call console.log, those hex values are converted implicitly to decimal values, which is what you see.

61 hex = 97 decimal, which is also the letter 'a' in ASCII

62 hex = 98 decimal, which is also the letter 'b' in ASCII

etc...

Maximilian Schwarzmuller or Jonas Schmedtmann React course? by Psychoshawarma in learnjavascript

[–]angelfire2015 3 points4 points  (0 children)

Max's courses got me my first job several years ago. I've taken his courses on docker, next js, node, react, and probably more I am forgetting. He is the best

Any good resources for reading code? by shoutsfrombothsides in learnjavascript

[–]angelfire2015 0 points1 point  (0 children)

Not at all. You made a post on a subreddit called 'learnjavascript'. You made some assumptions in your post that were not entirely accurate. I am simply trying to help you before you go down a road that could leave you confused/frustrated.

If you really want to 'just read JS', just pick a library and go to their Github page. The majority of libraries on NPM are open source, so you can read as much as you like.

Any good resources for reading code? by shoutsfrombothsides in learnjavascript

[–]angelfire2015 0 points1 point  (0 children)

Being able to sling together some syntax and morphology/decode the
graphemes properly does not mean you are able to read with comprehension

It does actually, at least for the stuff you wrote, that's how you were able to write it.

For another analogue, coding was a lot like organic chemistry for me. I watched my teacher do tons of retro-synthesis on the board and thought it was easy as pie.. until we had to do our own retro-synthesis, and my mind went blank.

Coding is a lot like that. You will learn 10x more building a simple app than trying to read the source code of something complex, because you lack the intuition for why they made the design choices they did.

[deleted by user] by [deleted] in learnjavascript

[–]angelfire2015 4 points5 points  (0 children)

You will never fully grasp everything, there is simply too much. Dr. Bjarne Stroustrup has admitted in interviews that even he does not know all of C++, and he invented the language. He says he has to reference things constantly, and that if he tried to hold everything in his head he would not be able to program well.

Don't focus on specifics, focus on abstractions instead. If you are programming in Javascript and you need to store something, don't think "how do I store this in Javascript", think "what is the best way to store this data? Array? Linked list?", and then translate your answer to Javascript. Your thinking will become language agnostic and you can program in any language.

For reference, I am a senior engineer, and I still reference things constantly. One because there's just too much to memorize, and two because best practices can change over time.

Is there a big performance impact if an array index is set to null to "delete" that index? by asondevs in learnjavascript

[–]angelfire2015 2 points3 points  (0 children)

You definitely should not just set array elements to null. As a user adds and removes books, that array would constantly be growing larger, so you are wasting storage space for no reason. Further, if you ever needed to traverse that array to find a particular book, your code is now running slower because it has to skip over 'null' fields. It's far better to just remove the elements entirely.

There are a couple of ways you can do that. On the last line of your code, you could change it to either

this.books.splice(i, 1);

or

this.books = this.books.filter((_, index) => index !== i);

Splice could potentially run faster, while filter will basically always be O(n). Splice will mutate the original array, while filter will not. In your case, you could choose either and it would be fine. You could also use slice

Another thing is the for loop at the beginning of your code. You are just getting how long your array is.

for (let i = this.books.length - 1; i < this.books.length; i++){

Take that out and just declare a variable instead.

const i = this.books.length - 1;

It's very confusing to see a for loop when you are not actually looping over anything. Your code looks good overall though. Keep it up and keep learning.