Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Created March 13, 2011 19:51
Show Gist options
  • Select an option

  • Save dustingetz/868369 to your computer and use it in GitHub Desktop.

Select an option

Save dustingetz/868369 to your computer and use it in GitHub Desktop.
wave robot api add participant trace
{
"events": [
{
"type": "WAVELET_SELF_ADDED",
"modifiedBy": "dustin.getz@googlewave.com",
"timestamp": 1300045450639,
"properties": {
"blipId": "b+c5hJ3nfVB"
}
}
],
"wavelet": {
"creationTime": 1300042639323,
"lastModifiedTime": 1300045450639,
"version": 2722,
"participants": [
"dustin.getz@googlewave.com",
"dustin-getz@appspot.com"
],
"participantRoles": {
"dustin-getz@appspot.com": "FULL",
"dustin.getz@googlewave.com": "FULL"
},
"dataDocuments": {
},
"tags": [
],
"creator": "dustin.getz@googlewave.com",
"rootBlipId": "b+c5hJ3nfVB",
"title": "code `null\u003d\u003dfoo` vs `foo\u003d\u003dnull`",
"waveId": "googlewave.com!w+c5hJ3nfVA",
"waveletId": "googlewave.com!conv+root",
"rootThread": {
"id": "",
"location": -1,
"blipIds": [
"b+c5hJ3nfVB"
]
}
},
"blips": {
"b+c5hJ3nfVB": {
"annotations": [
{
"name": "conv/title",
"value": "",
"range": {
"start": 0,
"end": 32
}
},
{
"name": "lang",
"value": "unknown",
"range": {
"start": 0,
"end": 32
}
},
{
"name": "spell",
"value": "sp+1ukQp7ZkJKi\nf\nvs",
"range": {
"start": 18,
"end": 20
}
},
{
"name": "lang",
"value": "en",
"range": {
"start": 33,
"end": 170
}
},
{
"name": "style/fontFamily",
"value": "courier new,monospace",
"range": {
"start": 56,
"end": 72
}
},
{
"name": "style/fontStyle",
"value": "italic",
"range": {
"start": 72,
"end": 170
}
},
{
"name": "lang",
"value": "en",
"range": {
"start": 171,
"end": 446
}
},
{
"name": "style/fontFamily",
"value": "courier new,monospace",
"range": {
"start": 205,
"end": 220
}
},
{
"name": "style/fontFamily",
"value": "courier new,monospace",
"range": {
"start": 306,
"end": 322
}
},
{
"name": "lang",
"value": "en",
"range": {
"start": 447,
"end": 893
}
},
{
"name": "spell",
"value": "sp+1ukQp7ZkJK8\nf\nscan",
"range": {
"start": 535,
"end": 539
}
},
{
"name": "style/fontFamily",
"value": "courier new,monospace",
"range": {
"start": 787,
"end": 796
}
},
{
"name": "link/manual",
"value": "https://gist.github.com/868350",
"range": {
"start": 867,
"end": 879
}
},
{
"name": "lang",
"value": "en",
"range": {
"start": 894,
"end": 1155
}
},
{
"name": "lang",
"value": "en",
"range": {
"start": 1156,
"end": 1270
}
},
{
"name": "style/color",
"value": "rgb(0, 132, 180)",
"range": {
"start": 1270,
"end": 1272
}
},
{
"name": "link/manual",
"value": "http://twitter.com/#!/search?q\u003d%23codestyle",
"range": {
"start": 1270,
"end": 1272
}
},
{
"name": "style/fontFamily",
"value": "\u0027Helvetica Neue\u0027, Arial, sans-serif",
"range": {
"start": 1270,
"end": 1272
}
},
{
"name": "lang",
"value": "unknown",
"range": {
"start": 1271,
"end": 1334
}
},
{
"name": "style/fontSize",
"value": "0.8333333333333334em",
"range": {
"start": 1272,
"end": 1542
}
},
{
"name": "style/fontFamily",
"value": "\u0027Helvetica Neue\u0027, Arial, sans-serif",
"range": {
"start": 1334,
"end": 1335
}
},
{
"name": "style/color",
"value": "rgb(0, 132, 180)",
"range": {
"start": 1334,
"end": 1335
}
},
{
"name": "lang",
"value": "en",
"range": {
"start": 1334,
"end": 1542
}
},
{
"name": "link/manual",
"value": "http://twitter.com/#!/search?q\u003d%23codestyle",
"range": {
"start": 1334,
"end": 1335
}
}
],
"elements": {
"0": {
"type": "LINE",
"properties": {
}
},
"171": {
"type": "LINE",
"properties": {
}
},
"170": {
"type": "LINE",
"properties": {
}
},
"32": {
"type": "LINE",
"properties": {
}
},
"1155": {
"type": "LINE",
"properties": {
}
},
"33": {
"type": "LINE",
"properties": {
}
},
"1400": {
"type": "LINE",
"properties": {
}
},
"1156": {
"type": "LINE",
"properties": {
}
},
"446": {
"type": "LINE",
"properties": {
}
},
"447": {
"type": "LINE",
"properties": {
}
},
"893": {
"type": "LINE",
"properties": {
}
},
"1334": {
"type": "LINE",
"properties": {
}
},
"894": {
"type": "LINE",
"properties": {
}
},
"1270": {
"type": "LINE",
"properties": {
}
},
"1271": {
"type": "LINE",
"properties": {
}
},
"55": {
"type": "LINE",
"properties": {
"indent": "1"
}
}
},
"blipId": "b+c5hJ3nfVB",
"childBlipIds": [
],
"contributors": [
"dustin.getz@googlewave.com"
],
"creator": "dustin.getz@googlewave.com",
"content": "\ncode `null\u003d\u003dfoo` vs `foo\u003d\u003dnull`\n\nA colleague tweeted: \nif (null !\u003d foo) In my 15 years of programming, I think I forgot an \u0027\u003d\u0027 twice... It doesn\u0027t \"read\" properly, IMHO.\n\nHe prefers to write code like if (cmd \u003d\u003d \"save\"), because if you read it left to right like a sentance, it fits with english grammar: if cmd is \"save\". Switch it up, it just reads wrong. I shared his opinion for a few years until switching styles six months ago. Here\u0027s why:\n\nWhen we\u0027re reading someone else\u0027s code, we usually don\u0027t read line by line, but rather scan until we find what we need. Code tends to follow along the left margins, so when scanning, thats where our eyes are. Thus, I prefer to put the most dominant part of any statement towards the left. To me, it reads better too: you only need to scan if \"save\", my brain fills in the rest based on context. This is more obvious in switch logic [github.com].\n\nOf course, these stylistic things don\u0027t really matter. Scannable code is great, but others may or may not agree. Maintaining \"other people\u0027s code\" is a daily task, so we plow through it and just try to fit in, because you can\u0027t break code you didn\u0027t change[1].\n\nThere are other reasons to use this style[2][3] which may or may not be applicable depending on your environment.\n\n[1] or pollute the history, or cause upstream merge annoyances\n[2] in Java, \"constant\".equals(foo) doesn\u0027t break if foo is null.\n[3] When switching between Java and SQL, its surprisingly easy to inadvertently write \u0027\u003d\u0027 instead of \u0027\u003d\u003d\u0027. An IDE will flag it, so who cares.",
"lastModifiedTime": 1300045406452,
"parentBlipId": null,
"version": 2701,
"waveId": "googlewave.com!w+c5hJ3nfVA",
"waveletId": "googlewave.com!conv+root",
"replyThreadIds": [
],
"threadId": ""
}
},
"threads": {
},
"robotAddress": "dustin-getz@appspot.com"
}
<div style="font-weight:bold">
code `null==foo` vs `foo==null`
</div>
<div>
<br>
</div>
<div>
A colleague tweeted:
</div>
<div style="margin-left:22px">
<span style="font-family:'courier new', monospace">if (null != foo)</span><span style="font-style:italic"> In my 15 years of programming, I think I forgot an '=' twice... It doesn't "read" properly, IMHO.</span><br>
</div>
<div>
<br>
</div>
<div>
He prefers to write code like if <span style="font-family:'courier new', monospace">(cmd == "save")</span>, because if you read it left to right like a sentance, it fits with english grammar: <span style="font-family:'courier new', monospace">if cmd is "save"</span>. Switch it up, it just reads wrong. I shared his opinion for a few years until switching styles six months ago. Here's why:
</div>
<div>
<br>
</div>
<div>
When we're reading someone else's code, we usually don't read line by line, but rather scan until we find what we need. Code tends to follow along the left margins, so when scanning, thats where our eyes are. Thus, I prefer to put the most dominant part of any statement towards the left. To me, it reads better too: you only need to scan <span style="font-family:'courier new', monospace">if "save"</span>, my brain fills in the rest based on context. This is more obvious in <a href="http://www.google.com/url?sa=D&amp;q=https%3A%2F%2Fgist.github.com%2F868350">switch logic</a> [github.com].
</div>
<div>
<br>
</div>
<div>
Of course, these stylistic things don't really matter. Scannable code is great, but others may or may not agree. Maintaining "other people's code" is a daily task, so we plow through it and just try to fit in, because you can't break code you didn't change[1].
</div>
<div>
<br>
</div>
<div>
There are other reasons to use this style[2][3] which may or may not be applicable depending on your environment.
</div>
<div>
<br>
</div>
<div>
<span style="font-size:0.8333333333333334em">[1] or pollute the history, or cause upstream merge annoyances</span><br>
</div>
<div>
<span style="font-size:0.8333333333333334em">[2] in Java, "constant".equals(foo) doesn't break if foo is null.</span><br>
</div>
<div>
<span style="font-size:0.8333333333333334em">[3] When switching between Java and SQL, its surprisingly easy to inadvertently write '=' instead of '=='. An IDE will flag it, so who cares.</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment