How to write an elegant Anliven-take sugar orm as an example

Source: Internet
Author: User

Objective

I recently like to write a very beautiful technical article called Anliven. First of all, the article must be original rather than soft-wide; second, after reading not only can quickly absorb technical points and get started to develop, but also can sympathize with the author's enthusiastic praise and eager to share the feelings of experience, let people feel brief Encounter, clairvoyant.

Anliven based on technical articles but also higher than technical articles, with a summary of experience, but because the author carefully to figure out every punctuation, segmentation and become elegant. A full of subjective feelings of the article but not to chew the boring, the author carefully pointed out that every need to pay attention to the technical highlights in the text such as the Dragon Water, so that readers are very enjoyable. Therefore, I think it is valuable to share an original technical article spirit, but if the icing on the cake makes the technical article elegant, it is a matter of fact, merit.


Sugar ORM

Redeeming my limited ability to write flowers, it happened that the day before yesterday when doing an Android project from GitHub accidentally found sugar this awesome ORM library. Unbearable preface hope Amway, so fiddling with pen and ink, on the one hand, I think the programmer how to write an elegant Anliven, on the one hand let everyone know this really good library.

What is Anliven

"Anliven" is the network vocabulary, as long as the definition of non-standardized protocol is a very subjective thing, I think Anliven should have the conditions include:

1. Open source. Only open source products will make people hard, not to represent hunted's acquisition, but only the people who love will understand a spirit (I low level only a star200 more open source projects, but I feel very happy).

2. Original. Even if it is a translation, you should add your own subjective experience. For only "practice is the only tool to test truth", if you do not try to talk about praise.

3. The article is clean and neat. 1..2..3 simple and clear instructions how to use, 4..5..6 direct when the description of technical highlights. Do not from "Today by subway meet black silk big wave sister" start, "this project finished the boss overtime pay not to" end, only talk about technology.

4. Has the field experience, has own insight, can sharply the Amway object to let the person fondle admiringly the reason. The reader has no shortage of starter developers, if there is not at least 2 project experience, with a thing I have used on the crazy write I love it, but there are other better wheels can replace, if no comment pointed out, not the time of the people.

5. Make no secret of your joy. If you have no confidence in the wheels you recommend, how can you prove to others that this is really a good thing to do right-turn and never miss? Do not use the conservative expression of the left to tell you the experience of the process of excitement, pleasure, is should let the reader empathy.

How to write gracefully

The word "elegance" I saw in technical articles, was first seen when learning laravel documents . People who have read the document are very polar: love don't want and scold don't want. I understand very well why people scold, the mindset of reading laravel documents is completely different from the reading mentality of the MSDN traditional education stereotype: it feels very light and the wording is soft and wide. To say that an open source project is very weak, it must be a portal dispute, wheel loyalty, but it is also a Anliven fun and one of the best, from the comments can learn more lessons, and these are based on the selfless sharing of danale experience. Therefore, the "elegance" of the writing, triggering a controversy, but it is a good thing to celebrate.

"Elegant" with a very strong bourgeois literary bourgeoisie, to be accustomed to pretend like a Wen Qing, bold "elegant" to write Anliven. Below, I say how I think I should write gracefully:

1. Read like a machine turn. "Exciting new features", "may be xxx", "worth to delve into", "beyond the imagination of the extreme" ..., is not very familiar? Think it over, and read it catchy. With these technology company's advertising language, is always more than open search engine to show off the Tang Dynasty more real choice, because although the rhetoric is not gorgeous, but the most easy to let developers feel, after all, accustomed to the translation of sentence patterns and words. Of course, if you can write the Luo guan in the pen, the Chinese science and technology blog should be a writers association.

2. A natural segment should not be too long. Want to express things a lot, very well, but you can be divided into several natural segments. Too long a natural segment may reduce the reader's interest in reading, in fact, this is not so much a user experience optimization, rather than to make people lazy, should not be applied to developers.

3. Figure. A picture of the top hundred words, with Visio,XMind,UML painting, too lazy qq screenshot is also a good choice.

4. Use brackets to reinforce the subjective attitude (like this, you look like I'm in the heart, hate-_-!! )。 Write in parentheses about your experience when describing technical points, and the reader will be able to experience a stronger subjective impression.

5. The code handles the details. Formatting tools that must be formatted,markdown , or blog editors, no one would like code without indentation. As much as possible to add comments, this will make readers moved.

6. Title, small title, bold. This is one thing that makes writing an article easier, not a burden on your writing. Because you are a science student, this is more in line with your thinking logic. If you don't know how to phrase it, just like I do with a little headline 1. 2..3 segment bar, do not need CSS decoration, other developers will see.

7. Good-natured bragging force. This will improve the reader's psychological "anchor point", that is, "Starbucks latte must be more expensive than KFC," the good-natured blow is that you are showing how you are loyal to the wheel, for example, I never use dagger or butterknife, My company's projects are all cut and copy, and did not see on-line running out of the problem (see? )。

8. Modest self-confidence, a trance of farting. Heavens beyond heavens, someone outside, who one night to see the million books, a bowl of food to eat under the heavy rice. Must not self-arrogant arrogant, should humbly accept comments in the correction, mentality is necessary. However, in order to improve the reader's interest in reading, gag, open-eyed fart, appeared "50% grasp it will be the best project on GitHub, 50% to grasp it will be the most rotten project on GitHub", this completely meaningless text, is fully encouraged by an act.

9. Put in the draft box, have a cup of tea and then open the change again. The last thing to remember is that you want to write a sympathetic Anliven, not a general technical summary, so refactoring is very necessary.

Think of something, on the improvisation, in fact, I am also lianbi for their own, Qinnengbuzhuo. Originally also want to Amway a little Bo I like to read a number of science and technology, but there is a suspicion of people's atmosphere, see I often forwarded the micro-Bo know what. If you have the next day to write a Anliven of your own impulse, also count this article is not written in vain. The following is the practice of their own written Anliven examples, I hope you like.

Android database incredibly can be so lightweight-sugar orm Simple Guide

The database operation under Android has always been a more troublesome thing, if written in the original, then in addition to database connection, version upgrade, basic query and other basic functions can be packaged reusable, business logic from schema to addition and deletion must be rewritten again. And more often, my project's database business logic is not so high performance requirements and complexity, therefore, choose an ORM library instead, is a very wise choice.

It's steady.

At present, the most well-known and most widely used Android ORM Open source project is Greendao, which comes from the famous Greenrobot (that is, the great gods who wrote Eventbus), ranked first on the GitHub Android ORM List all year round. The advantages and disadvantages of the online have been many articles in-depth interpretation, here no further.

In combination with my own business needs, the Greendao is still too heavy-it needs to generate the model with a Java Desktop program (in fact, Java is my only Android.) That's not going to kill me, so I've been working on the database business logic in a native way until my heart crashes. Once again on GitHub, the results immediately fell in love with the second-ranked Sugar ORM and instantly applied to the project.

Sugar ORM Features

Simple, is the highest evaluation of sugar. KISS (the Keep it simple and stupid) principle is the perfect presentation that requires experienced code refactoring to do so. I've always been a loyal fan of Orm, and I'm first thinking about fast development, never thinking about performance. From the Entity Framework to the eloquent ORM to the sugar ORM, although sugar is not as powerful as the former two, I think it's enough, why?


The project itself thinks--the simplest way to handle database business

Let's take a look at Sugar's introduction and how to say it yourself:

A simple, concise, and clean integration process with minimal configuration.

(The simplest, most straightforward, and invigorating integration process with minimal configuration)

Automatic table and column naming through reflection.

(using reflection without intervening to automatically generate tables and fields)

Support for migrations between different schema versions.

(Supports migration of different versions of database collections)

So sugar integration, in the end how simple to what extent. Look at the Bean's writing:


An example of a bean

Unlike Greendao, you need to create beans exclusively with desktop tools. Does not need you to write the table to create the code, does not need to write the addition and deletion to change the code (of course the business code or to write, he understands your mood, does not understand your heart), is simply to this degree. If the attribute has drawable and so on do not want to deposit the database field, then add @ignore is good, arbitrary.

Configure 2 steps to get it done

The sugar has only 2 configurations.

1. Modify your Androidmanifest.xml

, depending on whether the database name, version, open log, or your project package name are included. Don't forget to add the overloaded application class parameter in the application tag with 2


Androidmanifest.xml Adding database Information

2. Add initialization and destruction to your application class.

One boot, one off. No need to worry about it when you set it up.


Add sugar environment settings in application want to get off work early, with QueryBuilder

ORM is the most powerful place in the OOP principle of the query operation, sugar to change the additions and deletions are sealed for you. Because it's simple enough, take the query as an example and include:

1.Id Query, FindByID

2. Simple SQL statement query, find

3. Complex RAW statement query, Findwithquery

3. Quantity query, Count


Do not write a long string of code, a word to be done

Complex point of business logic, write good SQL statements, with executequery or findwithquery execution, choose which function to see your mood, happy good. There is a pit that needs attention, sugar has a naming convention, if the field is named after the hump naming method, it needs to be replaced by an underscore, such as "Testunderscore" needs to be changed to "Test_underscore". But you do not have to worry too much, sugar has provided the function stringutil.tosqlname ("Testunderscore"), automatically help you to convert the name.

I don't know about you, I'm on him anyway.

In fact, in the beginning of the development of Android, using the Xutils framework of the domestic great God has been relatively shallow to understand the ORM, but then give up to stick with the original write all the code. Because of neglect, only know Greendao, but it is too troublesome to use. After discovering sugar, all kinds of data also do not intend to save preference, I still insist not to use annotation library, but sugar will certainly be used in every project after. Because it's simple, you can put more energy into the business logic, this is not the idea of the open source community. I don't know about you, I'm on him anyway.

Related information

Project Address: Https://github.com/satyan/sugar

Document: Http://satyan.github.io/sugar/getting-started.html

P.S.

Hoping to help who, hey.

Build a group of their own, hope that the broad knot, especially like me, the brain short-circuit without react recklessly anroid, iOS native want to do something of friends.

App Independent Development Group 533838427

How to write an elegant Anliven-take sugar orm as an example

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.