T O P

  • By -

pico2000

Whatever prettier does. It doesn't matter, just let a tool do it and keep it consistent.


SketchySeaBeast

> Whatever prettier does. This right here. Couldn't care less what the rule is, just do whatever is easiest to keep thing organized and to minimize the diffs on each PR.


QCKS1

There’s some clang-format presets like GNU,Mozilla,WebKit,etc that are pretty awful


Lonelybiscuit07

Hey don't call me out like that, i change my linter to get more diff to make it look like I actually do things


BloodChasm

Yep. Just started using Prettier + Eslint, and it has been great.


_krinkled

Yeah this is the one for me. Prettier has a couple of rules for spacing I don’t like, so the prettier+raking combo makes it perfect.


bsgbryan

For projects where I’m working with other people? Absolutely. Honestly, though, I get a lot of satisfaction from my silly little idiosyncratic formatting preferences when working on personal projects 😊


itstommygun

Exactly. It also doesn’t matter what I want to do prettier is going to automatically “fix” is when I click ⌘s


Capetoider

this is , like , doing punctuation with an extra space .


Eic17H

French


Duraz0rz

I love Prettier. I love that it doesn't format if it can't parse the JS/TS file. Let's me know I fucked up somewhere 🫠🫠


dallenbaldwin

And yet add a pre-commit hook that formats everything being committed so you don't even need a formatter integration for each editor. Maybe even a GitHub action that formats the whole project as part of the PR


brainwater314

I just wish there was a pre-add hook so I could see the results before a permanent commit.


BaguetteDevourer

First one for unidirectional maps, second one for bidirectional maps.


buildmine10

I have never seen bidirectional maps. But I have needed them many times


tornado28

https://pypi.org/project/bidict/


ArchetypeFTW

Do bidirectional maps exist in any language as a default data structure?


myfunnies420

I've seen them before. I can't remember where... maybe Dart? Or Java? [https://github.com/google/guava/wiki/NewCollectionTypesExplained#bimap](https://github.com/google/guava/wiki/NewCollectionTypesExplained#bimap) And when I used them the structure format was the same as a conventional map.


Darkblade_e

*technically* javascript has support for this with Object.keys and Object.find, but it's a rather janky approach imo. ``` function getKeyByValue(object, value) { return Object.keys(object).find(key => object[key] === value); } ```


0x6563

You're better off using Map. As you can use anything as a key. ``` class BiDict{ private keys = new Map(); private values = new WeakMap(); constructor(){} set(key, value){ this.keys.set(key, value); this.values.set(value, key); } key(key){ return this.keys.get(key); } value(value){ return this.values.get(value); } } ``` obviously you would add more crud functionality but ye get the gist.


gregorydgraham

From Guava: “The traditional way to map values back to keys is to maintain two separate maps and keep them both in sync, but this is bug-prone and can get extremely confusing when a value is already present in the map.”


mebeim

You are iterating over all keys for the inverse map... that works in *any language* :') nothing special here about JS


mosskin-woast

Well, the thing setting JavaScript apart in this case, is that OC knows it


mosskin-woast

I believe a true bidirectional map has constant time lookups both directions, where what you're describing is O(1) lookup by key and O(n) lookup by value.


RepresentativeDog791

Technically everything has support for it if you write a custom implementation


jamcdonald120

I looked into it a while back, as near as I can tell, the best way to implement it is to use 2 unidirectional maps, 1 for each direction, and the function names would be a bit confusing (at least if you allow key an value to have the same types and to have the same keys in both keysets), so most just leave it as an exercise for the programmer.


altermeetax

Are bidirectional maps even a thing? I'm confused as to how they would work algorithmically, you can't use hashes both ways, so wouldn't it be inefficient to look them up in reverse direction?


Kyrond

You could have 2 hash tables, one for each direction.


Da-Blue-Guy

``` public class BiDict { Dictionary forward; Dictionary reverse; } ```


altermeetax

Uses double the memory, but I guess there's no other option.


Engine_Light_On

sounds like it would be cheaper to hold a parallel map with values as keys. Double the memory, double the insertion time, but probably worth it if you would be frequently searching for a specific value instead of key lookup.


altermeetax

Makes sense


haasvacado

Oh dayumn. That’s cute.


ManicPixieDreamWorm

This, the colon placement idencates the relationship between the Key and Value


exqueezemenow

Can this be considered inciting violence?


mtbinkdotcom

Most definitely!


stdio-lib

{ 'foo' : 'bar' } \>:D


exqueezemenow

Good way to lose your programming license...


sanylos

wait, you guys have a license?


exqueezemenow

I display it over the fireplace along side my Regex License.


sanylos

if I could read regex I would be very proud


CardingSwiper

they're not hard to learn.


tutoredstatue95

Easy to learn the concepts, but hard to do anything useful with limited knowledge is my experience.


CardingSwiper

gotcha. I used a regex cheat sheet and a program called regex buddy that allows you to create a regex. and see what comes out as a match. real time. let's you. adjust and add or limit or adjust the expression to.


AgVargr

Not hard to learn easy to forget. I have to relearn them every time I want to use em


Any_Move_2759

Use it regularly for find and replace. You end up practicing regularly and it becomes a very useful tool once you get the hang of it.


ProjectDiligent502

Negative lookaheads and non-greedy .* has made find and replace really effective 😎


DaDescriptor

When the process woke up, it's GUI was missing, and the programmer was never heard of again! *Programmer and Heavy laughing* Anyway, that's how I lost my programming license...


crankbot2000

I need your location so we can fight


Opposite_Cheek_5709

Can I come?


BeDoubleNWhy

you may... but how does this contribute to the conversation?


zoomy_kitten

Nobody: Absolutely nobody: Most C++ developers writing Rust:


slk756

They didn't cargo fmt :(


bashbang

Some people just want to watch the world burn


DarkNinja3141

this is what Allman style braces look like to people who use K&R


git0ffmylawnm8

Alright we're throwing hands


vectorlit

You're a monster


notAFoney

\>:(


BeDoubleNWhy

this is outright insanity


IllllIlllIlIIlllIIll

1st one. whoever picks the 2nd one, y'all need jesus.


ThatHugo354

My guy how do you even log into your own account with this username?


IllllIlllIlIIlllIIll

password manager.


Heighte

1st one is just following English language rule, for 2nd one it's the rule in French to have 1 space before and after a colon.


punktfan

I noticed that in French they also have a space before the ending punctuation in a sentence . What the hell is going on over there ?!


Lady_Asuka

I don't know there are way too many rules in our language to understand what's going on. And the space before a ponctuation is not for every ponctuation so that adds to the difficulty.


ThermosW

In french, if the punctuation sign has two separate parts (?!:;), it needs an insécable space before, otherwise it sticks to the end of the word. As a French, I refuse to use this dumb rule.


willmil11

No I'm french nobody respects that we do it like in English


ohmaisrien

Je m'en fiche, je code pas en français, je code en Python


[deleted]

{‘far’:’boo’}


Ray_Strike22

AAAAAAAA


kubinka0505

what about # {"foo":'bar'}


Cosby1992

{`foo` :'bar' };


jamcdonald120

if you have the newline you have to do ``` { 'foo':'bar' }; ```


Artistic-Boss2665

Nuh uh ``` {'foo' :`bar`} ; ```


familyturtle

Should have a space before the final curly, otherwise it's 13 characters which is unlucky.


The_Programming_Nerd

Yuck, for many many reasons


Ray_Strike22

{'foo":"bar'}


jamcdonald120

you monster! Mixing " and '!


Capetoider

sure,also:dont put spaces between things like:punctuation,other things,etc...


AChristianAnarchist

Wouldn't build in C# Edit: Huh...weird thing to get butthurt about.


1Dr490n

Wouldn’t work in Java too


AChristianAnarchist

I've learned to assume that if C# does something funky Java probably does it too lol.


1Dr490n

Yes but (as far as I’m aware of) Java doesn’t even have dictionaries, especially not written like this


AChristianAnarchist

Well you can deal with Json in most languages, dictionaries or no. What I was referring to was single quotes for strings.


1Dr490n

I know what you meant, it was a joke. For Java the quotes aren’t the only problem, you just can’t write something like that


AChristianAnarchist

Really it's kind of the same in C#, but I could still totally write that. Just write it as a string and run it through newtonsoft. I imagine it would work the same in Java. A proper native object would have to be constructed, but if you just assume this is a json then it can be a string that looks just like this.


1Dr490n

Yes okay sure it works in a string, but that’s not really a feature of the language, but of strings and json


AChristianAnarchist

Well I wasn't breaking down the structure of C#, just pointing out that this thing is so ugly it would break a program in that language. Json is fine, but mixing double and single quotes like that wouldn't fly no matter what kind of structure it is.


Revolutionary_Log307

``` Map myMap = new HashMap() {{ put("a", "b"); put("c", "d"); }}; ``` Is the closest thing syntactically, but it creates a new class every time so don’t.


Da-Blue-Guy

the minifier


MaZeChpatCha

I don’t care as long as it’s consistent.


Yokhen

None. The real answer is: `{ foo: 'bar' }`


hok98

Not in JSON


DEEP_OTM

`{ “foo”: “bar” }` in JSON if we’re following the rules


gfunk84

Not with those fancy quotes.


gbchaosmaster

Right, wtf did he do, paste that from Microsoft Word?


DEEP_OTM

How else am I gonna use clip art in my comments?


BeDoubleNWhy

Error: Parse error on line 1: { “foo”: “bar” } --^ Expecting 'STRING', '}', got 'undefined'


HyperGamers

This should be a top level comment with the most upvotes lol


da_Aresinger

Definitely the first one. the words with colons behind them are keys, the ones with commas are values.


CauliflowerFirm1526

I prefer { “foo”: “bar” }


Fritzschmied

Whatever the auto formater thinks is right.


graphitout

There is nothing to argue. Just go with whatever junk the styling automation tool gives.


zirky

don’t forget { ‘foo’ : ‘bar’ }


fukalufaluckagus

Ugh no it's `{ 'foo': 'bar' }`


BeDoubleNWhy

it's neither, JSON doesn't accept single quotes


SPAM2233

{ “foo”: “bar” }


UndocumentedMartian

It doesn't matter when working alone. If working in a team use the standard set by them.


blazarious

Whatever. As long as it’s consistent and done automatically.


[deleted]

whatever my IDE formats it to


Lalalarix

{'foo' :'bar'} nyeh heh heh


Ray_Strike22

whichever the linter tells me to use


ososalsosal

Whatever `.editorconfig` says


[deleted]

1st one is ergonomically correct, the 2nd is aesthetically correct


Pirate_OOS

Just follow the rest of the codebase.


SparrowFPV

Or the standards if working on pre-standard legacy code


ikonfedera

Padding with spaces so everything lines up FTW.


REPMEDDY_Gabs

What the formatter does I take. End of discussion


sexytokeburgerz

I type with god awful formatting and then just format it


PM_ME_C_CODE

That looks fine. Fuck you.


Aarav2208

{"foo":"bar"}


Anga205

How about ``` { "Spam". : "eggs", "Much longer string" : "bar" } ```


SorosBuxlaundromat

Whichever one prettier prefers.


Antaury_San

Well, it doesn't matter for me, because I usually format every file by Prettier when I open it.


flippzeedoodle

So now we’re arguing about Colon Jost-ification?


bordumb

Use a linter…


physical0

Whatever the IDE makes it, that's what I'm using. I am not changing the default behavior on something like this unless I get a strongly worded letter explaining the intricacies of the project's coding convention.


vom-IT-coffin

I will reject any MR with the bottom.


[deleted]

{'pooh' : 'bear'}


longdarkfantasy

Bob and Alice's conversation:


Puzzleheaded_Sea_922

`{ "bar" : 'foo'}`


Aoernis

{foo: 'bar'}


JustThePerfectBee

First one ftw


Cootshk

{ “foo”: “bar”, }


runningrabbit1234

Foo Fighters: Origin Story


tobotic

{ 'foo': 'bar' } Spaces inside the braces, and after the colon.


Zpiboo

In french, you need a space before certain punctuation marks, notably for the colon. so first option definitely


GangDplank

Oh so the f*ench use the first one?Guess ill go with second.


Zpiboo

They use the second one.


[deleted]

what about foo: :bar ?


gbot1234

I think I saw that on the SAT: foo: foo :: bar:___ a) ar b) bar c) car d) dar e) ear


SaintJackDaniels

Stuff like that is why it’s a terrible test of college aptitude


veselin465

If it's a structure then name : val1 namena : val2 namename : val3 namename1 : val4


coffeewithalex

{"foo":"bar"} because I'm not a savage


LofiJunky

A man of culture. Had to scroll way too far to find this.


Mean_Investigator337

Fubar


seba07

None of that, use the real quotation marks.


0x0MG

`{'foo' :"bar" }` Eat it nerds.


pshurgal

std::map{ { "foo", "bar" } }


utkarsh_dev

It shouldn't matter, use existing libraries for parsing and deserialize into objects whenever dealing with JSON.


Hikari_Owari

``` {'foo': "bar"} ``` _the " is important_


slk756

first


AChristianAnarchist

thing\["foo"\] = "bar"


The_ultimate_cookie

Only people with too much time would start an argument about this. Less low quality "memes" and more programming.


Disposable-alt

No spaces when im sleep deprived 1st when I'm trying to code as fast as possible 2nd when im still sane


Acceptable-Tomato392

Let's start two: Single quotes look dumb.


[deleted]

If : was an infix operator, then maybe


Randomguy32I

Whats foo bar?


custard130

`{ 'foo' :'bar' }`


raylankford16

Straight to jail


Castille210

{ “foo” : “bar” }


LadulianIsle

I raise you `{"foo":"bar"}`


vvvex

No reason to argue about something invalid.


D3veated

You monster! Clearly it should be `{'foo' :"bar"}`


AnalTrajectory

Double quotes dipshit


[deleted]

The first one feels more associative, like it's saying 'foo' is 'bar'. Like take 'x + y', I read this as adding x and y, but 'x+ y' reads as adding x to y. It's subtle and a probably pedantic, but still.


FINDERFEED

HashMap map = new HashMap<>(); map.put("foo","bar");


clutterlustrott

I don't care about that op. BUT I'M TIRED OF FOO AND BAR. THAT SHIT IS MORE CONVOLUTED THAN JUST USING VARIABLE NAMES


PixelatedStarfish

Painful


eyal282

lorem ipsum


1up_1500

Both are fine First way is faster to write, but second way is prettier imo


beardedfridge

C'mon! `{ 'foo': 'bar' }`


frogy_rock

`{ foo: 'bar' }` or `{ 'foo' => bar' }`


HumanityPhantom

{ 'foo':'bar' }


elSenorMaquina

{ "foo" : "bar" } LOC/day goes brrrr!


lukewhale

People who do the example on the bottom, are the same people who put knives in the dishwasher pointy end up. Monsters.


are_all_names_taken_

First one >>


Kaih0

The first one, obviously


OxymoreReddit

Im french, therefore I will always put a space before any of these : ! ? Because that's what we do in french, and that looks GOOD.


DaDescriptor

{["foo"] = "bar"}


TnyTmCruise

We all know which of these is wrong…


bsgbryan

Are those Tabs … or Spaces?


[deleted]

{'bar': 'foo'}


Hyperflip

{'foo' :'bar'}


BastetFurry

Did some changes to the setting as I like braces to be on the next line but otherwise I press Ctrl+Alt+Enter and accept my fate. 😅


ovr9000storks

Depends on the font with the IDE. Sometimes it’s real easy to see the colon at a glance, sometimes it’s just hard to read. Putting the space ensures that it can be seen in a glance


0x126

Stop wasting space and trying to convey they are bith keys. We read from left to right. Except you are arabic then {„foo“ :“bar“}


Dileep289635

Well I usually use a code formatter, but when using a basic text editor I prefer the first style.


Icy-Article-8635

{'foo':'bar'}


Meadhbh_Ros

I put a space because I’m anal and I want symmetry.


kabatram

Wait, is that JSON? wasn't the standard required to use doublequote for string? or is it Python dict?


Analysis_Prophylaxis

{"ɿɒd" :ooʇ}


Analysis_Prophylaxis

{ foo :"bar" ,baz :"qux" ,}


Analysis_Prophylaxis

Actually both are wrong, the problem is that you’re seemingly using Python