Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature currently requires accessing the site using the built-in Safari browser.
Damit hast du mich wirklich gekriegtAnother Few Bytes in Rust (Queen)
Sowas schonmal gelesen? Der eine Autor disst den anderen ... im gemeinsamen BuchOur running example for sorting will be a music playlist, displayed as a table. Each track is a single row, and each column is an attribute of that track, like artist, title, and running time. Imagine that a graphical user interface presents the table, and that clicking the head of a column causes the playlist to be sorted by that attribute; clicking the same column head again reverses the order. Let's look at what might happen in response to each click.
The variable tracks below contains a playlist. (One of the authors apologizes for the other author's musical tastes.) Each element is indirect, a pointer to a Track. [...]
package main
import (
"fmt"
"os"
"sort"
"text/tabwriter"
"time"
)
type Track struct {
Title string
Artist string
Album string
Year int
Length time.Duration
}
// Helper type needed for helper functions:
type byArtist []*Track
// Helper functions, so sort.Sort knows what to do:
func (x byArtist) Len() int { return len(x) }
func (x byArtist) Less(i, j int) bool { return x[i].Artist < x[j].Artist }
func (x byArtist) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
var tracks = []*Track {
{"Go", "Delilah", "From the Roots Up", 2012, length("3m38s")},
{"Go", "Moby", "Moby", 1992, length("3m38s")},
{"Go Ahead", "Alicia Keys", "As I Am", 2007, length("3m38s")},
{"Ready 2 Go", "Martin Solveig", "Smash", 2011, length("3m38s")},
}
func length(s string) time.Duration {
d, err := time.ParseDuration(s)
if err != nil {
panic(s)
}
return d
}
func printTracks(tracks []*Track) {
const format = "%v\t%v\t%v\t%v\t%v\t\n"
tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0)
fmt.Fprintf(tw, format, "Title", "Artist", "Album", "Year", "Length")
fmt.Fprintf(tw, format, "-----", "------", "-----", "----", "------")
for _, t := range tracks {
fmt.Fprintf(tw, format, t.Title, t.Artist, t.Album, t.Year, t.Length)
}
tw.Flush()
}
func main() {
fmt.Println("One of the authors apologizes for the other author's musical tastes:")
sort.Sort(byArtist(tracks))
printTracks(tracks)
}
$ go run main.go
offenbart den vermeintlich schlechten Musikgeschmack:One of the authors apologizes for the other author's musical tastes:
Title Artist Album Year Length
----- ------ ----- ---- ------
Go Ahead Alicia Keys As I Am 2007 3m38s
Go Delilah From the Roots Up 2012 3m38s
Ready 2 Go Martin Solveig Smash 2011 3m38s
Go Moby Moby 1992 3m38s
Fürwahr, wobei ich persönlich mir da keine Sorgen machen würde, schließlich hat Microsoft selbst ja verkündet, dass mit Windows 10 Schluss sein wird. Man möchte sich ja auch gerne an diesem neuartigen SaaS beteiligen, das Google, Amazon, und Co. so großzügig die Taschen füllt.wobei….. „….. Windows 66“ ist schon gruseliger Gedanke