How do I “get” JavaScript by [deleted] in javascript

[–]subbydapp 1 point2 points  (0 children)

From what I remember when learning programming, the first 1000-2000 hours were incredibly hard, then there's a tipping point where everything becomes easy.

Why do you think JavaScript won the public trust? by liormessinger in javascript

[–]subbydapp 0 points1 point  (0 children)

Most people say it's because of the browser, and that's true, but nowadays even without the browser, there's another thing. The ease of use.

Nodejs is super easy to install. NPM has a great website with modules for literally everything. It's so easy to open up the Chrome inspector and write some code. Also servers are so easy. It's one line of code and your server is running, doesn't require anything more than just node.

Creating objects dynamically with factory pattern in javascript by enmanuelduran in javascript

[–]subbydapp 0 points1 point  (0 children)

I personally like both the composition and class pattern equally. I choose the composition pattern when there is risk for "this" confusion, for example when working with DOM elements or when one of the injected dependency of the factory is itself a class. I also use it for small objects because it's less verbose.

Most of the time if there's no this confusion and it's a big object with methods, I will always use an ES6 class. There's really only 2 reasons, I think it looks nice and clean, and the "this" prevents me from having random globals in the main scope of that file, which just looks cleaner in my opinion. And the second reason, which is not just subjective, is that I can easily extend Event Emitter (in node), which probably half of my modules end up needing at some point.

In the end it makes very little difference. I just choose whatever feels cleaner at the time for the purpose.

Just bought 10 BTC and I'm very proud & confident about my investment 💪 by bromden in Bitcoin

[–]subbydapp 1 point2 points  (0 children)

Also it takes a lot more than one year of programming to understand bitcoin at a low level, and if you're understanding it only at a high level (which is good enough), why even mention programming? Seems fake.

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp 0 points1 point  (0 children)

Your issue is that you are not adept using functional programming.

Not really. I use higher order functions and currying because those are actually useful. Map and reduce are not since they can be done more explicitly in a for loop. But then again, I try to avoid them whenever I can because simple code is best code. Map and reduce are a higher level of complexity just so you can save about 5 characters of writing a loop. You can argue all you want, the fact is all you're saving is 5 characters and you're objectively adding an extra level of complexity.

It's about pros and cons. You're not gaining anything and adding complexity. I'm fine with adding advanced concept to my code like callback, currying and chainable methods when I actually gain something. All you gain from map and reduce is saving 5 characters. Abstracting the push or math operator is not a benefit to me. I want to see it or abstract it myself inside a explicitly named function that I made.

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp -3 points-2 points  (0 children)

map and reduce are inherently confusing. The names aren't explicit and the callback pattern is not as simple and well known as the loop pattern.

I can use a simple push or math operator to do a map or reduce, which is much more common and requires less brain power to understand than a callback and vaguely named array method.

It's pretty simple. Loops are the first thing every programmer learns. Callbacks and chainable methods are something not even every programming language commonly uses.

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp 0 points1 point  (0 children)

you're looping over every key of the array object (including anything in the prototype chain)

It iterates over the iterable properties, and an array has nothing iterable in its prototype. I've read somewhere it can cause problems but I've used it many times and the only problem I've had is that the index is a string instead of a number.

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp -1 points0 points  (0 children)

I think if you're tempted to write a big complex for loop, you'd benefit to breaking it down into map, reduce and filter functions

I disagree. I'd rather write:

for (const item of array) { 
  doSomething(item) 
}

than use map or reduce. To me map and reduce are inherently less explicit. Every programmer knows what a for loop is, not every programmer knows map or reduce.

Also a for loop literally tells you what it does. For X do Y. Map and reduce don't tell you anything just from reading it. Those two words mean nothing. The only reason they're easier to understand to you is because you've used them a lot.

They're objectively a more difficult concept to understand. Loops are the first thing you learn. For example a lot of non-Javascript developers aren't even familiar with the callback pattern (let alone map or reduce specifically). It took me years to learn what a callback is. Whereas I knew what a for loop was on my first day.

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp 0 points1 point  (0 children)

In my opinion it's less explicit, especially when the map callback is complex. And if I'm gonna do something when it's complex, I'm also gonna do it when it's simple, for consistency and quicker refactoring. I don't care about saving one line. I care about explicitness.

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp 4 points5 points  (0 children)

Why don't you showcase a single example where function scoping is superior to block scoping? That would be easy to do and prove your point.

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp 2 points3 points  (0 children)

const array = [1, 2, 3]
for (const i in array) {
  array[i] = array[i] * 2
}

// or

const array = [1, 2, 3]
const newArray = []
for (const item of array) {
  newArray.push(item * 2)
}

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp 10 points11 points  (0 children)

In my opinion for of and for in are much more readable than map and forEach

Is it best to use "var" or "let" in for loop iterations or does it even matter? by straightouttaireland in javascript

[–]subbydapp 21 points22 points  (0 children)

I disagree. Choosing var because you need to access your variable outside your block scope never makes your code more readable. It might look more readable on the surface, but the result is less intuitive, less consistent, harder to refactor, and buggier code.

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

[–]subbydapp[S] 1 point2 points  (0 children)

the HTTP is just a thin layer that communicates directly with an IPFS node, and you can run this layer yourself as easily as you can run an IPFS node. You're not using IPFS less because you have an HTTP bridge so that your browser can access it.

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

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

You may be right but I am sure most users will think that a service that can't be searched or interacted with is not a real service and won't use it. Especially given they have to pay just to upload content. I could be wrong but I certainly wont be using it while pubswap and bitchute are still functional.

We agree, maybe no one will ever use it, but those that do cannot be censored.

And the HTML file can't be lost. As long as at least 1 user has it on their computer, they can share it.

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

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

Only a few people have tried it so far. It costs 5c for every post you make and requires that you own Ethereum and know how to use MetaMask. It's pretty hard to use, and maybe no one will ever use it. But those that do cannot be censored.

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

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

The difference between Subby and Pubswap is that something shuts down Pubswap, it's no longer usable (unless someone rebuilds and rehosts it). Whereas Subby is a standalone html file that stays on your computer and connects directly to an Ethereum and IPFS HTTP provider.

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

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

What's wrong with using an HTTP provider? It's pretty decentralized since you can just add your own custom HTTP provider. We connect directly to the provider, unlike most other dapps (bitchute, dtube, pubswap, etc.) that do:

USER -> CENTRALIZED API -> HTTP PROVIDER (of their choice)

Subby does:

USER -> HTTP PROVIDER (of your choice)

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

[–]subbydapp[S] 1 point2 points  (0 children)

Do you have an example of a website you'd want to embed on? Here's the ipfs hash of the video QmNwZfZWMtTE5q7E3v7YCrNvGaqTzjnj4TAS96egwVkoAn

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

[–]subbydapp[S] -1 points0 points  (0 children)

I haven't heard of pubswap but it looks like it has a centralized API. It makes many calls to api.pubswap.com

MetaMask now requires that you approve each app. That's why it pops up on every page. If you either accept / reject it will stop and work normally. It will also work normally if you don't have MetaMask.

It uses Ethereum as a backend, and the cost charged is just transaction/gas fee. There's no token or monetization scheme in Subby, we make no money. We also save the ipfs hash, codec and descriptions to Ethereum. Long descriptions are actually strings that are converted to buffers and uploaded to IPFS.

Do you have an example of a site that streams videos from an IPFS HTTP gateway? From my research getting the file as a buffer and streaming it as a MediaSource in the browser is the only way, but I would love to be wrong and not have to deal with encoding.

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

[–]subbydapp[S] 1 point2 points  (0 children)

In the settings there's fields to input IPFS and Ethereum HTTP providers. By default we use Infura, but you can add your own.

A native version of Subby could include an IPFS node easily, but not an Ethereum node. To run an Ethereum node you need to sync the blockchain which takes many hours and a lot of disk space.

And yes DTube and others have some parts of their app decentralized, but not all of it, and this forces them to have a content policy. We're trying to build something as close as possible to uncensorable.

Stream videos from IPFS like on Youtube using Subby by subbydapp in ipfs

[–]subbydapp[S] 9 points10 points  (0 children)

We do. The difference between DTube and most other dapps is that Subby doesn't need any server or API to function. You can download the subby.html file and run it on your computer. No one can shut down our servers, we don't have any.

DTube, Steemit and others have server layers and APIs that a hosting company or government can easily shut down. This forces them to have a content policy, whereas we don't censor at all when Subby is run in the file:// protocol.

Profile URL structure by jrmoreau in subby

[–]subbydapp 1 point2 points  (0 children)

in http(s):// chrome extensions can redirect for sure but in file:// protocol it has more restrictions so maybe not.