From Java to go, to Java "not translated"

Source: Internet
Author: User
Tags cassandra value store
This is a creation in Article, where the information may have evolved or changed.

Introduction:fitness landscapes, Cassandra, and making things worse

in Lisp, you don ' t just write your Toward the language, you also build the language to toward your program. As you are ' re writing a program think "I Wish Lisp had such-and-such an operator." So you go and write it. Afterward you realize this using the new operator would simplify the design of another part of the program, and so on. Language and program evolve together ... The end your program would look as if the language had been designed for it. And when the language and program fit one another well, your end up with the code which is clear, small, and efficient.
–paul Graham, programming bottom-up

In evolutionary biology, a fitness landscape is a by-the-visualising the relationship between genotypes and Reproductiv E success. Each possible variation of a genotype are projected onto a position on a map, and the height of the terrain at that Positio N represents the reproductive success associated with that variation. We can then imagine a sequence of genetic variations as a walk on the This map. The rules for walking a fitness landscape is that can only move around the map in small steps–no sudden leaps from One position to Another–and steps in the ' wrong ' direction, i.e. those that decrease your reproductive success, is Puni Shed with a lower chance of being able to continue your walk around the map. A walker placed near a peak on the map would therefore tend to move ' uphill ' towards that peak, rather than heading The valleys to go and search for a higher peak elsewhere.

No one has translated this paragraph yet

I'll translate.

This by visualising the behaviour of genetic algorithms enables us to see how it was that such algorithms would tend to Settle on "locally optimal" solutions rather than finding a "global optimum", and highlight a problem with purely incremen Tal approaches to exploring a range of possible designs:if each increment must deliver a quantifiable improvement, and SU Dden leaps to another point on the map is forbidden, then we could get stuck on a locally optimal design and never reach th E peaks that might is found elsewhere. If we ' re already sitting at the top of a locally optimal solution, there could be nowhere we can go. Sometimes, things has to get worse before they can get better.

In Opencredo ' s October Cassandra Webinar, I described the distributed Key-value store Cassandra as "unsolving" the problem s solved by relational database management systems, in order to achieve performance and scalability characteristics that W Ere beyond the reach of such systems. Cassanda throws out almost all of the data management features of the RDBMS, replacing them with a simple yet powerful mod El of data addressing based on two-dimensional keys. If We understand how this model works, and how do I work with it, then we can get the exceptional performance out of Cassan Dra But if we try to use Cassandra as an RDBMS, we'll quickly discover that Cassandra are a worse RDBMS in almost Every possible.

No one has translated this paragraph yet

I'll translate.

If We visualise the space of possible data management systems as a fitness landscape, we can see this Cassandra and an RDBMS sit at (or near) different "peaks" in the Landscape:by very loose analogy with evolution, they occupy different "ni Ches ", being optimised for different things. Of course, Cassandra didn ' t evolve from the RDBMS by small increments:its developers didn ' t begin with an RDBMS and progr Essively make it worse until the Cassandra data model hoved into view. Rather, Cassandra is the result of choosing a different starting point altogether in the design space.

When I first started learning Google's Go language, a few months ago, my immediate impression was of a language that had D Eliberately been made worse in multiple ways. I ' ve heard fellow developers complain bitterly about what retrograde its design are, how wilfully ugly and restrictive. For them, using Go is like rolling down into a trough in the fitness landscape. They couldn ' t wait to scramble back up to the heights of elegance and productivity offered by Java. But even as I winced at some of the things Go is taking away from me, I wondered what it is optimising for instead. What if Go wasn ' t a worse Java, but a better something else? I decided to stick with the language, and see what it might has to teach me about a area of the programming language des IGN space I hadn ' t explored before.

No one has translated this paragraph yet

I'll translate.

Go:what is It good for?

A programming language is low level and its programs require attention to the irrelevant.
–alan Perlis, epigrams on programming

As much as it has it detractors, Go also have many fans:people who love programming in it, who find it satisfyingly produ Ctive, who read their own Go code with pleasure and confidence. Let's assume they ' re not simply deluded. What's Go doing for these developers?

A commonplace among go programmers is this other people's code written in go are usually easy to read and under Stand. When I am given the task of implementing a new TerraForm provider, I went to the TerraForm codebase and read through the Implementation code for other providers. I was able to follow it almost immediately, and had a working prototype of my own provider up and running the same day. While the "readability" is a very subjective notion, Go code have some specific properties which seem to aid comprehension.

Chiefly, Go sacrifices expressiveness for uniformity . I like to think of programming as a "creative" activity, and as part of the I like to develop within each system an idiom Which fits the I think about the domain. Paul Graham described this approach many years ago as one in which your first build up the language do want to write your Program in, then write the program itself, so, the latter seems to fall naturally and expressively out of the domain A Bstractions you are created for it. Go provides very limited means for doing This:no macros, no generics, no lambda expressions, a approach to Erro R handling which makes "fluent" APIs impracticable, and so on. Almost all the tricks I ' ve built to the years for creating embedded DSLs in Java or Ruby or Clojure is simply Unavai Lable. You basically has no choice but to write your program in + or less "vanilla" Go.

No one has translated this paragraph yet

I'll translate.

On the other hand, if there ' s one complaint I ' ve heard consistently from my fellow developers over the years, it's that th EY can ' t understand my code until they also understand the set of abstractions I ' ve introduced in order to make the logic of it easier to express. Once They do understand them, they ' re usually comfortable (Once or twice I ' ve had-roll something back out because Nobod Y else could see the point of it; They were usually right, in retrospect).Je ne regrette rien. But you do has to work to get people over the initial hurdle; And that means thattheyHas to work, too. This was practicable in a small, close-knit team where can just wander over to someone ' s desk and talk them through SOM Ething unfamiliar, but it presents a challenge when your codebase would be is read and potentially worked on by hundreds or th Ousands of people, situated in different timezones, across a period of decades. That's Google's reality, and Go is optimised for that scenario.

Here ' s a concrete example. Suppose we wanted to append an exclamation mark to each of the strings in a collection, creating a new collection with the Modified strings. In Kotlin, which would be

Val plain = listof ("foo", "Bar", "Baz") val exclaimed = strings.map {it + "!"}

In Go, you could write

func mapstringtostring (Input []string,  mapper func (String)  string)  []string {output := make ([]string, len ( Input)) For index, item := range input {output[index] = mapper (item)} Return output} func main ()  {plain := []string{"foo",  "bar",  "Baz"} Exclaimed := mapstringtostring (Plain, func (s string)  string {             return s +  "!"         }) fmt. Println (exclaimed)} 

But it ' s terribly clunky. Go ' s lack of generics means so you had to write as mapStringToString a mapper between collections of both fixed types–you can ' t WR Ite a generic from an map array T R of-an array of, as-can in almost any other strongly-typed modern Lang Uage. The lack of lambda functions means so you had to write out the function signature in full just to pass the string modif Ying function into the mapper. It hardly seems worth it; You might as well just write:

Func Main () {plain: = []string{"foo", "Bar", "baz"}exclaimed: = Make ([]string], Len (plain)) for index, item: = Range Plain { Exclaimed[index] = Item + "!"} Fmt. Println (exclaimed)}

No one has translated this paragraph yet

I'll translate.

While Go does support passing around functions (and this is occasionally useful), it doesn ' t really support th e Use of functions to build up composable abstractions, feel like extensions to the language. It favours the concrete, inline expression of logic, with function calls acting primarily as a mechanism for structured PR Ogramming. "Concrete and inline" means "you can see it in front of the where it's happening" –which makes life A Lot easier in the programmer who have to follow the execution path of a unfamiliar piece of code.

The same philosophy is on work in Go's approach to library inclusion, which are to compile and link everything staticall Y. It means that whenever your ' re using a library you have the library's source code to hand, in a predictable location in The path Go uses to locate external dependencies. Ctrl-click in an IDE would take you straight to the declaration site of the function you ' re using. The general principle are to favour the transparent and ready-to-hand over the remote and opaque, the concrete and literal Over the abstract and magical. It ' s like speaking a language without metaphors.

Once you accept that "vanilla" Go are all of them, it may be the best think of it as a sort of DSL for performing disk and Network I/O (the standard libraries is comprehensive and immediately useful), enriching and transforming data (Go's Struc T types is extremely good for the) and efficiently parallelising work (Goroutines is a well-thought-out low-level abstr Action for parallel execution). These features make it excellent for "systems" programming, where you ' re typically concerned with discrete, chainable oper Ations–read in this text file, parse it contents as CSV, emit a sum of the values in the third Column–and a concrete, Imperative style of programming naturally fits the problem space. It's less well-suited to "applications" development, where you need a wider range of metaphors to express multiple Perspec Tives on the application ' s domain. I would not, for example, want-to-use Go-to-write software which relied heavily on a "Actor"-based approach–you can Do It, but it ' s Pretty clunky compared to the expressiveness offered-Akka by Scala's case classes and pattern matching.

No one has translated this paragraph yet

I'll translate.

What Java developers Can learn from Go

A language that doesn ' t affect the the-the-the-think about programming, are not worth knowing.
–alan Perlis, epigrams on programming

Returning to Java (and Kotlin) development after a couple of months of Go development, I found myself more willing to cons Ider the concrete and immediate expression of some piece of program logic might serve better than trying A more generic version of the same logic that might never is re-used in practice. I discovered the value of a certain sort of "plain speaking" in code.

I also found myself feeling just a little less patient with the amount of behind-the-scenes magic that the Spring Boot Framework puts into play, and wishing for something a little more lightweight and transparent. When your work is in a language this makes different trade-offs, for different purposes, then the trade-offs involved in your Familiar, comfortable environment become more apparent:you see what's is sacrificing in return for the things you Valu E.

Learning Go won ' t teach you any exciting new computer science concepts, or introduce you to a whole new paradigm of Softwa Re development (for, try Idris). But it'll give you a better understanding of the breadth and variety of the design space for programming languages, at a time when mainstream languages generally seem to be converging (Kotlin are rather like Swift, was rather like Typescript, E TC). Sometimes it isn ' t the innovative new features that distinguish a language, but it choice of restrictions.

No one has translated this paragraph yet

I'll translate.
All translations in this article are for learning and communication purposes only, please be sure to indicate the translator, source, and link to this article.
Our translation work in accordance with the CC agreement, if our work has violated your rights and interests, please contact us promptly
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.