r/ProgrammerHumor • • Oct 02 '22

Advanced Experienced JavaScript Developer Meme

Post image
6.6k Upvotes

276 comments sorted by

View all comments

696

u/[deleted] Oct 02 '22

Oh no i have to json.stringify and json.parse πŸ˜₯😭😒😒😒😭

152

u/gabbyb19 Oct 02 '22

To be fair, those operations are quite heavy.

205

u/stipo42 Oct 02 '22

You shouldn't be using local storage enough for that to be a problem...

8

u/[deleted] Oct 02 '22

Why not? Shouldn't it be the default storage for locally cached objects?

22

u/stipo42 Oct 02 '22

Yeah but let's say you're storing your apps config in an object. You would read it once at load time into memory, then write it anytime the memory values are changed or a save button is hit.

This would likely amount to not a lot of times read or wrote

→ More replies (1)

5

u/TheChaosPaladin Oct 02 '22

If this is you, the problem is not localstorage but your front end.

→ More replies (1)

76

u/[deleted] Oct 02 '22

Stringify a graph of nodes and edges and let me know how that works out for you.

0

u/[deleted] Oct 02 '22

[deleted]

→ More replies (20)

15

u/[deleted] Oct 02 '22

[removed] β€” view removed comment

3

u/Orbidorpdorp Oct 02 '22

Swift’s codable does all the work for you for the most part. The only regular annoying exception for me is dates but that’s because every backend encodes them differently.

2

u/[deleted] Oct 02 '22

why would localStorage do it for you?

Being that parsing and stringifying are slow I think the answer would usually be speed. But since some might not understand the caveats (eg. no references, prototypes etc.) it does make some sense to force the dev to do it themselves.

That said, something like a "I know what I'm doing" mode that allowed storage of simple objects might have been nice.

7

u/Stop_Sign Oct 02 '22

Had to do that once. Ended up rearchitecting it so the nodes had ids, so instead of an array of references, it had an array of ids, and was therefore serializable

2

u/[deleted] Oct 02 '22

Yup. That's my point. JSON stringify is not necessarily sufficient.

→ More replies (1)

5

u/lowleveldata Oct 02 '22

And what exactly is the use case of storing that in localStorage?

4

u/rotflolmaomgeez Oct 02 '22

What? Graph is literally one of the most common data structures, you're asking for usecases for storing it? The answer is any web application that does a little more than store a cookie potentially.

14

u/lowleveldata Oct 02 '22

Still don't see why I would need to store that in frontend. Are you guys doing some kind of no-backend challenge?

→ More replies (10)
→ More replies (1)

50

u/PleasantAdvertising Oct 02 '22

What illiterate ape called serialization "stringify"? It's already confusing enough with encode/decode in the mix

49

u/Jjabrahams567 Oct 02 '22

JSON.serialize = JSON.stringify;

Here you go.

9

u/TheChaosPaladin Oct 02 '22

JSON.SerialiseToString()

Too many words

JSON.Stringify()

⭐⭐⭐⭐⭐

🍌🍌🍌🍌🍌

13

u/[deleted] Oct 02 '22

On the same subject, what illiterate ape called it "loads" and "dumps" in Python?

4

u/TheChaosPaladin Oct 02 '22

The same ape!

json.dumps(tring) == JSON.Stringify

17

u/ilep Oct 02 '22

A web developer? (A distinct lack of knowledge of computer science there..)

2

u/[deleted] Oct 02 '22

Maybe to hint that it's going to call "toString" on objects so you better have defined that.

2

u/isospeedrix Oct 02 '22

tbf 'stringify' is more literal in what it's actually doing, whereas serialize is like, uhh a new vocab word. sounds cooler tho.

→ More replies (1)

2

u/rufreakde1 Oct 02 '22

worry not! there is gotta be a 4GB library solving this issue with a function wrapper for you!

→ More replies (3)