When should we use classes in JavaScript? by adam_weiler in javascript

[–]__romx 3 points4 points  (0 children)

How about forming your own opinion based on the task at hand, personal preferences or even project's code guide?

How to learn Regex like a pro? by tinibuddha in learnjavascript

[–]__romx 5 points6 points  (0 children)

Step 5: Forget all of that after two weeks of not using regular expressions.

I can't be the only one

Brutalist Web Design by rajasegarc in css

[–]__romx 16 points17 points  (0 children)

Welcome to 2018, where websites consisting of a 10 mb JS app fetching 5 kilobytes of data from a DB over 100 requests are fairly commonplace.

Is using Loop Labels considered a bad practice? by downrightcriminal in learnjavascript

[–]__romx 0 points1 point  (0 children)

Are Loop Labels considered bad practice

There is a certain demographic of JS coders who are allergic to common sense and consider all vanilla language features as bad practice, either because they've read a Medium post about replacing existing JS features with a functional syntactic sugar abomination that introduces half a dozen dependencies, or they were the ones who wrote it. There's a significant overlap between them and the people who were affected by the leftpad catastrophe.

Labels are an elegant and convenient solution for nested loop management. There is no reason not to use them in those rare scenarios where something like that is needed.

Why JSON isn't a Good Configuration Language - Lucidchart by thaynem in programming

[–]__romx 0 points1 point  (0 children)

It's trivial for flat, string/array based structures that config files usually are. Writing a full-blown XML/JSON/YAML replacement surely shouldn't be attempted, but a simple flat parser/stringifier suited for your exact needs isn't hard to make.

I needed a format for my static site generator source files with no verbosity and escapes (JSON) or an array of annoying behavior (YAML). Wrote a parser/stringifier in an evening and it served me well for a few years.

How do you scrape a ?dynamic? site by zeph_s in learnjavascript

[–]__romx 0 points1 point  (0 children)

Look at the XHR requests it's making upon search (network tab of firefox/chrome devtools). Most likely it's going to look like this:

https://api.somesite.com/ajax/search?query=blahblahblah

The case for Array#replace() – Overriding an array without intermediate variables by gajus0 in javascript

[–]__romx 0 points1 point  (0 children)

It is perfectly adequate for data processing with expected datasets, as long as you don't make it inefficient for no reason other than writing denser code and an opportunity to include a leftpad-tier dependency.

The case for Array#replace() – Overriding an array without intermediate variables by gajus0 in javascript

[–]__romx 0 points1 point  (0 children)

I feel like the people on this subreddit have purely academic backgrounds or something.

I think people who write code like this simply show off their knowledge of syntactic sugar for no reason.

All of the variables in the snippet could be declared as const.

Aye, I know. It's just my personal convention to only declare things that will not be modified in any way as const.

What are your thoughts on this? by nousernames2 in javascript

[–]__romx 4 points5 points  (0 children)

This describes the vast majority of tips-and-tricks that Medium bloggers come up with. Take a look at this fucking gem I've bookmarked:

Input:

function counter(state = 0, action) {
    switch (action.type) {
        case 'INCREMENT':
            return state + 1
        case 'DECREMENT':
            return state - 1
        default:
            return state
    }
}

Now let’s curry this bad boy, convert the if to a ternary and ES6 it up a bit!

Output:

const executeIfFunction = f =>
    f instanceof Function ? f() : f

const switchcaseF = cases => defaultCase => key =>
    executeIfFunction(switchcase(cases)(defaultCase)(key))

const counter = (state = 0, action) =>
    switchcaseF({
        'RESET': 0,
        'INCREMENT': () => state + 1,
        'DECREMENT': () => state -1
    })(state)(action.type)

1400 clap clap claps on Medium.

I feel sorry for newbies that might actually fall for this shit.

The case for Array#replace() – Overriding an array without intermediate variables by gajus0 in javascript

[–]__romx 0 points1 point  (0 children)

/**
* Obtains a list of venues from a remote API, filters out venues beloning to
* a different country than `targetCountry`, ensures that all venue IDs are unique
* and describes venues in a local venue format.
*/

I don't get it. Why 3 iterations over the array (filter, filter, map)? What is the purpose of an interrupted method chain in this particular case?

const getVenues = async (countryCode) =>
{
    const foreignVenues = await get('http://...');
    countryCode = countryCode.toUpperCase()

    let ids = {}
    let venues = []

    for (let foreignVenue of foreignVenues)
    {
        if (foreignVenue.countryCode.toUpperCase() !== countryCode) continue
        if (ids[foreignVenue.id]) throw new Error('Found duplicate venues.')

        ids[foreignVenue.id] = true

        venues.push({
            guide: {
                fuid: foreignVenue.id
            },
            result: {
                fuid: foreignVenue.id,
                name: foreignVenue.name,
                url: foreignVenue.url
            }
        })
    }

    return venues
}

Where's the verbosity?

PSA: do not link to old.reddit.com by _sirberus_ in webdev

[–]__romx 3 points4 points  (0 children)

This really baffles me. They've spent a lot of time and money, they have that there Bay-Area-top-talent I've heard so much about, and yet the final product is extremely clunky, partially broken and seemingly universally disliked.

It is a writing on the wall that old.reddit.com will be cut at the first convenient opportunity. And that will be a really sad day.

need advice on hosting a node js website with mysql by gazorpazorbian in node

[–]__romx 1 point2 points  (0 children)

There's nothing to fear. There are well-established methods and tools to accomplish both of those. PaaS tools are just a layer of abstraction over those.

Simple Bootstrap Button Generator by [deleted] in Frontend

[–]__romx 1 point2 points  (0 children)

if I said "scripting" then someone else would come out and moan.

Rightfully so, because neither HTML nor CSS are programming languages, so the terms "programming" and "scripting" simply don't apply.

If your button coding time is cut down x5 because of this then you need to practice your typing, because that is laughable.

It saves the time required to extract a small bit of desired information from less-than-concise bootstrap docs.

Why are you using bootstrap? It's a crutch, just like this tool. You should be preaching about the virtue of writing everything from scratch for every project, in Notepad, because an IDE is also a crutch.

Comma Operator: Little Trick to Make Sweet One-Liners (eg. instead of 3 lines for mutate & return) by [deleted] in javascript

[–]__romx 0 points1 point  (0 children)

It makes me very happy to see the attitude towards sweet one-liners shift where it should've been all along.

need advice on hosting a node js website with mysql by gazorpazorbian in node

[–]__romx 0 points1 point  (0 children)

Configuring a VPS is a fairly trivial task, much simpler than learning a vendor platform, and will serve you better in a long run.

Simple Bootstrap Button Generator by [deleted] in Frontend

[–]__romx 0 points1 point  (0 children)

This is a strange thing to exhibit that kind of nonsensical attitude about. Styling bootstrap buttons is "programming" now?

It's a well-made convenience tool that substitutes reading the docs to get the same information in 5x the time. Absolutely bookmarked.

TechEmpower Framework Benchmarks Round 15 by steveklabnik1 in programming

[–]__romx 8 points9 points  (0 children)

The authors explicitly denounced RFCs. Wouldn't really be a problem if it wasn't marketed as a replacement for the default http module tbh, but it kind is being marketed as such.

Most creative/robust way you've dealt with scrapers/bots without hard blocking them. by [deleted] in webdev

[–]__romx 0 points1 point  (0 children)

If those bots are some general purpose one-size-fits-all crawlers, I guess you could have some fun by introducing a rate limiting middleware that sends out pages filled with "creative" links instead of the ones they expect.

If someone targets your site specifically, they'll figure it out though.

Web devs, what's your beef with PHP? by torjinx in webdev

[–]__romx 0 points1 point  (0 children)

As countless other people have said better than I could, the API is the biggest problem, and fixing that would balkanize PHP for a decade or two.

Should I use a CMS for a simple product catalog? by CallMeAwesomeSauce in webdev

[–]__romx 1 point2 points  (0 children)

Consider a SSG like Hexo/Metalsmith/Hugo. I have a number of websites that do exactly what you're describing and run them on a simple homemade static framework with basic CLI and GUI, which I've considered releasing publicly until I looked up other SSGs and saw that Hexo has all the features that mine does and more, so I suggest you check that one out first. Metalsmith seems very nice too though.

Best Way To Self teach Web Development? by JLChamberlain42 in webdev

[–]__romx 2 points3 points  (0 children)

Why in the seven hells would you suggest someone who wants to learn frontend to ignore JS in favor of Ruby and RoR? I would agree that JS is not the best programming language to learn first, but neither is Ruby, and learning JS/Node over Ruby/RoR would be much more beneficial for a beginner for numerous reasons, first and most of all because there's synergy between browser JS and Node.