Indentation level is four spaces.
Only space characters may be used for indentation. No tabs.
Empty lines must not be indented. (This is implied by the no trailing white space rule.)
case lines should be indented with four spaces, and statements within the case should be indented with another f...
Source code and comments should generally not exceed 80 characters per line and rarely if ever exceed 100 characters per line, including indentation.
The character limit must be judged on a case by case basis. What really matters is the semantical “density” and readability of the line. Making l...
If a line approaches the maximum character limit, always consider breaking it down into multiple statements / expressions instead of wrapping the line.
Break before operators.
Break before the . in chained method calls.
popupMsg("Inbox notification: You have "
+ newMsgs + &...
One variable per declaration (and at most one declaration per line)
Square brackets of arrays should be at the type (String[] args) and not on the variable (String args[]).
Declare a local variable right before it is first used, and initialize it as close to the declaration as possible.
Declaration annotations should be put on a separate line from the declaration being annotated.
@SuppressWarnings("unchecked")
public T[] toArray(T[] typeHolder) {
...
}
However, few or short annotations annotating a single-line method may be put on the same line as the method if...
Runnable r = () -> System.out.println("Hello World");
Supplier<String> c = () -> "Hello World";
// Collection::contains is a simple unary method and its behavior is
// clear from the context. A method reference is preferred here.
appendFilter(goodStrings::cont...
return flag ? "yes" : "no";
String cmp = (flag1 != flag2) ? "not equal" : "equal";
// Don't do this
return (flag ? "yes" : "no");
Redundant grouping parentheses (i.e. parentheses that does not affect evaluation) may be used if t...
You can also use line-height to center vertically a single line of text inside a container :
CSS
div {
height: 200px;
line-height: 200px;
}
That's quite ugly, but can be useful inside an <input /> element.
The line-height property works only when the text to be centered spans ...
Note the use of {{.}} to output the item within the template.
package main
import (
"fmt"
"os"
"text/template"
)
func main() {
const (
letter = `Dear {{.}}, How are you?`
)
tmpl, err := template.New("letter").Pa...
First, here's what can happen when text/template is used for HTML. Note Harry's FirstName property).
package main
import (
"fmt"
"html/template"
"os"
)
type Person struct {
FirstName string
LastName string
Street string
Cit...
Using regular recursion, each recursive call pushes another entry onto the call stack. When the recursion is completed, the application has to pop each entry off all the way back down. If there are much recursive function calls it can end up with a huge stack.
Scala automatically removes the recurs...
With methods in golang you can do method "chaining" passing pointer to method and returning pointer to the same struct like this:
package main
import (
"fmt"
)
type Employee struct {
Name string
Age int
Rank int
}
func (empl *Employee) Promote() *...
It is possible to specify log destination with something that statisfies io.Writer interface. With that we can log to file:
package main
import (
"log"
"os"
)
func main() {
logfile, err := os.OpenFile("test.log", os.O_RDWR|os.O_CREATE|os.O_APPEND,...
It is also possible to log to syslog with log/syslog like this:
package main
import (
"log"
"log/syslog"
)
func main() {
syslogger, err := syslog.New(syslog.LOG_INFO, "syslog_example")
if err != nil {
log.Fatalln(err)
}
l...
context.lineCap=capStyle // butt (default), round, square
Sets the cap style of line starting points and ending points.
butt, the default lineCap style, shows squared caps that do not extend beyond the line's starting and ending points.
round, shows rounded caps that extend beyond the ...
context.lineJoin=joinStyle // miter (default), round, bevel
Sets the style used to connect adjoining line segments.
miter, the default, joins line segments with a sharp joint.
round, joins line segments with a rounded joint.
bevel, joins line segments with a blunted joint.
<!doctype...
context.strokeStyle=color
Sets the color that will be used to stroke the outline of the current path.
These are color options (these must be quoted):
A CSS named color, for example context.strokeStyle='red'
A hex color, for example context.strokeStyle='#FF0000'
An RGB color, for e...
context.fillStyle=color
Sets the color that will be used to fill the interior of the current path.
These are color options (these must be quoted):
A CSS named color, for example context.fillStyle='red'
A hex color, for example context.fillStyle='#FF0000'
An RGB color, for example ...
context.lineWidth=lineWidth
Sets the width of the line that will stroke the outline of the path
<!doctype html>
<html>
<head>
<style>
body{ background-color:white; }
#canvas{border:1px solid red; }
</style>
<script>
window.onload=(function(){...