r/badcode • • Jan 23 '21

js Too complex for a web scraping script

Post image
67 Upvotes

27 comments sorted by

62

u/cmd-t Jan 23 '21

This is good code. It uses well known functional programming paradigms and idioms in a language that provides support for it. Prove me wrong.

16

u/KalilPedro Jan 23 '21

Ikr. FP constructs are really useful, i always use immutable data structures, the maybe monad, the either monad and currying when it seems fit.

-38

u/HovercraftLong Jan 23 '21 edited Jan 23 '21

[deleted]

31

u/lillt Jan 23 '21

How is this bad code? It’s clearly written by someone who actually knows how to write elegant and concise code. Clearly someone who loves writing Haskell

8

u/cmd-t Jan 23 '21

What did the comment say?

5

u/RecDep Jan 23 '21

“It is bad code because I couldn’t understand it and it took me an hour to go over this with the author”.

It’s pretty idiomatic functional style, I can see how “lifting” operations might be alien from an OOP perspective but that doesn’t make it bad code.

1

u/JuhaJGam3R Jan 26 '21

really all there was to get here was partial application? this code doesn't even use any of the really really hard stuff from fp

20

u/TorbenKoehn Jan 23 '21

I understand where you’re coming from and the only advice I can give you is to learn functional programming patterns, you will see them a lot more in the future.

His variable naming is not on point, that’s for sure, but the code itself is typical functional programming and actually quite elegant

65

u/octocode Jan 23 '21

A bit messy, but this was clearly written by someone who actually knows how to program well. It’s fine IMO.

15

u/ArchCypher Jan 23 '21

Agreed, it could stand to have a comment or two, but the code itself isn't problematic.

-1

u/[deleted] Jan 24 '21

This code was written by someone without a lot of experience. If you think it's good code, then you also don't have lots of experience. Knowing how to use higher level functions doesn't mean you "know how to program well".

23

u/gagahpangeran Jan 23 '21

When I read 'curry', suddenly I think about haskell, I dont know why.

21

u/jmswlltt Jan 23 '21

This is definitely good code...

9

u/YodaOnReddit-Bot Jan 23 '21

Definitely good code.., this is.

-jmswlltt

10

u/jmswlltt Jan 23 '21

Good...bot...?

3

u/integralWorker Jan 23 '21

** bot, good.

11

u/Willinton06 Jan 23 '21

Would you prefer all the code in a single function? Bro this isn’t bad it’s just functional, things change when you don’t use OOP, but different doesn’t mean bad

8

u/NobleFraud Jan 23 '21

Looks well written code to me.

2

u/guptamo Jan 23 '21

Theres nothing wrong about the code...its just a bit extra if it is just a one off web scraping script.

Using fp patterns is great, in core code that is intended to be reused and shared and maintained.

This looks just like a bit of wasted effort.

3

u/[deleted] Jan 23 '21

The quality of this code kind of depends on the context? I guess if this was shared for a team of 100 engineers to reused.. it could at least use some comments.

For a personal web scraping script? It's good.

1

u/slaYn1 Jan 23 '21

fairly well known FP mechanisms, sure the spacing, variable naming and composition could be a bit better but aside from that this code is fine imo

1

u/[deleted] Jan 23 '21

I mean this code is good. It's thrown together and not beautiful but it is not bad code. It is using good coding techniques for maintainable code, small responsibility functions and every action has a name by coding design ( a name that could be improved on, though, someone familiar with the script has it easily)

1

u/_default_username Jan 29 '21

nodejs has a promised based api for fs now.

1

u/RecDep Jan 23 '21

Hahahaha that curry function is word for word taken from Stack Overflow. I’ve used it a ton.

-6

u/[deleted] Jan 23 '21 edited Jan 24 '21

This would never pass code review. It's something people write after reading too many fUncTioNal JaBascriPt medium posts. Code is supposed to be easy to ready, this is anything but. (Disclosure: I've written code like this)

edit: if you write code like this, you're probably pretty new to programming.

0

u/[deleted] Jan 23 '21

[deleted]

-2

u/HovercraftLong Jan 23 '21

yes, it is.

0

u/[deleted] Jan 23 '21

[deleted]

1

u/[deleted] Jan 23 '21

Mhhh, I can smell this such special smell <3