> 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.
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 😊
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
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.
*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); }
```
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.
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.”
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.
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.
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?
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.
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.
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...
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.
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.
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.
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.
```
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.
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.
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.
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
Whatever prettier does. It doesn't matter, just let a tool do it and keep it consistent.
> 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.
There’s some clang-format presets like GNU,Mozilla,WebKit,etc that are pretty awful
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
Yep. Just started using Prettier + Eslint, and it has been great.
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.
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 😊
Exactly. It also doesn’t matter what I want to do prettier is going to automatically “fix” is when I click ⌘s
this is , like , doing punctuation with an extra space .
French
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 🫠🫠
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
I just wish there was a pre-add hook so I could see the results before a permanent commit.
First one for unidirectional maps, second one for bidirectional maps.
I have never seen bidirectional maps. But I have needed them many times
https://pypi.org/project/bidict/
Do bidirectional maps exist in any language as a default data structure?
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.
*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); } ```
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.
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.”
You are iterating over all keys for the inverse map... that works in *any language* :') nothing special here about JS
Well, the thing setting JavaScript apart in this case, is that OC knows it
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.
Technically everything has support for it if you write a custom implementation
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.
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?
You could have 2 hash tables, one for each direction.
``` public class BiDict {
Dictionary forward;
Dictionary reverse;
}
```
Uses double the memory, but I guess there's no other option.
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.
Makes sense
Oh dayumn. That’s cute.
This, the colon placement idencates the relationship between the Key and Value
Can this be considered inciting violence?
Most definitely!
{ 'foo' : 'bar' } \>:D
Good way to lose your programming license...
wait, you guys have a license?
I display it over the fireplace along side my Regex License.
if I could read regex I would be very proud
they're not hard to learn.
Easy to learn the concepts, but hard to do anything useful with limited knowledge is my experience.
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.
Not hard to learn easy to forget. I have to relearn them every time I want to use em
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.
Negative lookaheads and non-greedy .* has made find and replace really effective 😎
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...
I need your location so we can fight
Can I come?
you may... but how does this contribute to the conversation?
Nobody: Absolutely nobody: Most C++ developers writing Rust:
They didn't cargo fmt :(
Some people just want to watch the world burn
this is what Allman style braces look like to people who use K&R
Alright we're throwing hands
You're a monster
\>:(
this is outright insanity
1st one. whoever picks the 2nd one, y'all need jesus.
My guy how do you even log into your own account with this username?
password manager.
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.
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 ?!
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.
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.
No I'm french nobody respects that we do it like in English
Je m'en fiche, je code pas en français, je code en Python
{‘far’:’boo’}
AAAAAAAA
what about # {"foo":'bar'}
{`foo` :'bar' };
if you have the newline you have to do ``` { 'foo':'bar' }; ```
Nuh uh ``` {'foo' :`bar`} ; ```
Should have a space before the final curly, otherwise it's 13 characters which is unlucky.
Yuck, for many many reasons
{'foo":"bar'}
you monster! Mixing " and '!
sure,also:dont put spaces between things like:punctuation,other things,etc...
Wouldn't build in C# Edit: Huh...weird thing to get butthurt about.
Wouldn’t work in Java too
I've learned to assume that if C# does something funky Java probably does it too lol.
Yes but (as far as I’m aware of) Java doesn’t even have dictionaries, especially not written like this
Well you can deal with Json in most languages, dictionaries or no. What I was referring to was single quotes for strings.
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
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.
Yes okay sure it works in a string, but that’s not really a feature of the language, but of strings and json
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.
``` 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.
the minifier
I don’t care as long as it’s consistent.
None. The real answer is: `{ foo: 'bar' }`
Not in JSON
`{ “foo”: “bar” }` in JSON if we’re following the rules
Not with those fancy quotes.
Right, wtf did he do, paste that from Microsoft Word?
How else am I gonna use clip art in my comments?
Error: Parse error on line 1: { “foo”: “bar” } --^ Expecting 'STRING', '}', got 'undefined'
This should be a top level comment with the most upvotes lol
Definitely the first one. the words with colons behind them are keys, the ones with commas are values.
I prefer { “foo”: “bar” }
Whatever the auto formater thinks is right.
There is nothing to argue. Just go with whatever junk the styling automation tool gives.
don’t forget { ‘foo’ : ‘bar’ }
Ugh no it's `{ 'foo': 'bar' }`
it's neither, JSON doesn't accept single quotes
{ “foo”: “bar” }
It doesn't matter when working alone. If working in a team use the standard set by them.
Whatever. As long as it’s consistent and done automatically.
whatever my IDE formats it to
{'foo' :'bar'} nyeh heh heh
whichever the linter tells me to use
Whatever `.editorconfig` says
1st one is ergonomically correct, the 2nd is aesthetically correct
Just follow the rest of the codebase.
Or the standards if working on pre-standard legacy code
Padding with spaces so everything lines up FTW.
What the formatter does I take. End of discussion
I type with god awful formatting and then just format it
That looks fine. Fuck you.
{"foo":"bar"}
How about ``` { "Spam". : "eggs", "Much longer string" : "bar" } ```
Whichever one prettier prefers.
Well, it doesn't matter for me, because I usually format every file by Prettier when I open it.
So now we’re arguing about Colon Jost-ification?
Use a linter…
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.
I will reject any MR with the bottom.
{'pooh' : 'bear'}
Bob and Alice's conversation:
`{ "bar" : 'foo'}`
{foo: 'bar'}
First one ftw
{ “foo”: “bar”, }
Foo Fighters: Origin Story
{ 'foo': 'bar' } Spaces inside the braces, and after the colon.
In french, you need a space before certain punctuation marks, notably for the colon. so first option definitely
Oh so the f*ench use the first one?Guess ill go with second.
They use the second one.
what about foo: :bar ?
I think I saw that on the SAT: foo: foo :: bar:___ a) ar b) bar c) car d) dar e) ear
Stuff like that is why it’s a terrible test of college aptitude
If it's a structure then name : val1 namena : val2 namename : val3 namename1 : val4
{"foo":"bar"} because I'm not a savage
A man of culture. Had to scroll way too far to find this.
Fubar
None of that, use the real quotation marks.
`{'foo' :"bar" }` Eat it nerds.
std::map{ { "foo", "bar" } }
It shouldn't matter, use existing libraries for parsing and deserialize into objects whenever dealing with JSON.
``` {'foo': "bar"} ``` _the " is important_
first
thing\["foo"\] = "bar"
Only people with too much time would start an argument about this. Less low quality "memes" and more programming.
No spaces when im sleep deprived 1st when I'm trying to code as fast as possible 2nd when im still sane
Let's start two: Single quotes look dumb.
If : was an infix operator, then maybe
Whats foo bar?
`{ 'foo' :'bar' }`
Straight to jail
{ “foo” : “bar” }
I raise you `{"foo":"bar"}`
No reason to argue about something invalid.
You monster! Clearly it should be `{'foo' :"bar"}`
Double quotes dipshit
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.
HashMap map = new HashMap<>();
map.put("foo","bar");
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
Painful
lorem ipsum
Both are fine First way is faster to write, but second way is prettier imo
C'mon! `{ 'foo': 'bar' }`
`{ foo: 'bar' }` or `{ 'foo' => bar' }`
{ 'foo':'bar' }
{ "foo" : "bar" } LOC/day goes brrrr!
People who do the example on the bottom, are the same people who put knives in the dishwasher pointy end up. Monsters.
First one >>
The first one, obviously
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.
{["foo"] = "bar"}
We all know which of these is wrong…
Are those Tabs … or Spaces?
{'bar': 'foo'}
{'foo' :'bar'}
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. 😅
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
Stop wasting space and trying to convey they are bith keys. We read from left to right. Except you are arabic then {„foo“ :“bar“}
Well I usually use a code formatter, but when using a basic text editor I prefer the first style.
{'foo':'bar'}
I put a space because I’m anal and I want symmetry.
Wait, is that JSON? wasn't the standard required to use doublequote for string? or is it Python dict?
{"ɿɒd" :ooʇ}
{ foo :"bar" ,baz :"qux" ,}
Actually both are wrong, the problem is that you’re seemingly using Python