Note: In May, I returned to Wuhan from the imperial capital. After half a month of traveling, I started to find a new job. In June, I chose one of the few mobile Internet companies in central China, A little bit of feeling-compared with the average level of Dongdu coomon and Wuhan coomon, the level of economic development of the two cities is as big as that of the two cities, it doesn't mean that there are no good programmers in Wuhan (I am also half of them), but that the average level is indeed not as good as that in other first-tier cities. It is also normal to think about it. giant companies are working together to attract a large number of programmers with extremely competitive compensation and benefits, while Wuhan's Internet development is still in its infancy, no matter the company's scale, fame, or the most practical salary and welfare aspects are not as good as the first-tier cities, it is naturally unable to attract a large number of programmers. I have been in the new company for nearly three months and gradually found some problems in the code, but these problems cannot be solved due to my ability for a short time, the rest is the programmer literacy questions I want to discuss.
Let me first talk about what I think is programmer literacy. I think it should include the following aspects: 1. Solid skills-a solid grasp of basic university courses such as operating systems and data structures, advocating basic useless theory must be a three-stream programmer. 2. learning mentality-be curious about what you call, take the time to understand what is behind the API, and understand how the system framework works. For new fields, be curious and try to learn more. 3. Be good at self-study, summarization, and questioning-no one will teach you after work, as long as you study hard and summarize it into blog or notes and other achievements, and then improve; when you encounter a problem that cannot be solved within the scope of your own capabilities, you must be good at asking for on-demand videos from the cool people, and the problem with a single point of view will often be answered with a single point of view. Let's take a simple example to discuss literacy 1. The requirement is as follows: the first 10 thousand pieces of data that have been sorted need to be taken as the final data. Considering the large data volume, if you create a new list, traverse the 5000 items in the old list and re-create the reference, there is a waste of space (the reference type occupies * 5000 bytes) bytes, and this method is clumsy. Therefore, after thinking a little bit, write the following code: copy the code list <item> rankitems = new arraylist <item> (); // generate data + sort... while (rankitems. size () & gt; 5000) {rankitems. remove (rankitems. size ()-1);} a simple analysis of the copied Code. It is a list implemented by arrays and called by the remove (INDEX) method. the source code of the arraycopy () method is as follows: copy the code/*** removes the object at the specified location from this list. ** @ Param Index * the index of the object to remove. * @ return the removed object. * @ Throws indexoutofboundsexception * when {@ code location <0 |> = size ()} */@ override public e remove (INT index) {object [] A = array; int S = size; If (index> = s) {throwindexoutofboundsexception (index, S) ;}@ suppresswarnings ("unchecked") e result = (e) A [Index]; system. arraycopy (A, index + 1, A, index, -- s-index); A [s] = NULL; // prevent Memory Leak size = s; modcount ++; return result;} copy Code system. arraycopy () is a native method and calls memcpy () in C language. Although the source address and DEST address of copy are the same, no new memory needs to be allocated, however, data in the arraylist can be deleted only after 5000 memory I/O reads and writes. The reason is that the Array Implementation Method of arraylist is not conducive to adding or deleting the array at the specified position. Therefore, the following code is generated after consideration: copy the code list <item> rankitems = new sorted list <item> (); // generate data + sort... while (rankitems. size () & gt; 5000) {rankitems. remove (rankitems. size ()-1);} is it higher than arraylist to copy the code and analyze the efficiency of listing deletion? The remove (INDEX) method of the lifecycle list is implemented as follows: copy the code/*** removes the object at the specified location from this {@ code lifecycle list }. ** @ Param location * the index of the object to remove * @ return the removed object * @ throws indexoutofboundsexception * If {@ code location <0 |> = size ()} */@ override public e remove (INT location) {If (0 <= Location & location <size) {link <E> link = voidlink; If (location <(Size/2) {for (INT I = 0; I <= location; I ++) {link = link. next ;}} else {for (INT I = size; I> location; I --) {link = link. previous ;}} link <E> previous = link. previous; Link <E> next = link. next; previous. next = next; next. previous = previous; size --; modcount ++; return link. data;} Throw new indexoutofboundsexception ();} It is very easy to copy the code into list. You only need to modify the reference of the object before and after the specified index object, but move the pointer to the specified index. Previously, we needed to move 1/2 lists in length, but the efficiency was not the highest. Can we also simplify the moving operation? Since the list is sorted and objects at the end of the list are deleted each time, we can use the removelast () method provided by the sorted list. The Code is as follows: copy the code list <item> rankitems = new sorted list <item> (); // generate data + sort... while (rankitems. size () & gt; 5000) {rankitems. removelast ();} copies the code to analyze the efficiency of removelast (). The removelast () method of the rollback list is implemented as follows: copy the code/*** removes the last object from this {@ code into list }. ** @ return the removed object. * @ throws nosuchelementexception * If this {@ code comment list} I S empty. */public e removelast () {link <E> last = voidlink. Previous; If (last! = Voidlink) {link <E> previous = last. previous; voidlink. previous = previous; previous. next = voidlink; size --; modcount ++; return last. data;} Throw new nosuchelementexception ();} The removelast () method used to copy the code into list does not have the operation to move the pointer. You only need to use the voidlink at the end of the list, you can delete objects at the end of the list, which is more efficient.
Programmer literacy issues that come to mind from a simple algorithm