Code details refactoring: Please point out my code (3)

Source: Internet
Author: User
Tags md5 hash

"PleaseCodeIt is an irregular routine activity in our group. With code review and detail refactoring as the main line, you can freely express your opinions and suggestions, it is also a storm of thinking. It makes sense to summarize and record this activity.

Target code
 1   Public   Static   String _ Computefilemd5hash ( String File ){ Return  _ Computemd5hash (_ openfile (File ));}  2   3   Private   Static   Byte [] _ Openfile (String  File)  4   {  5 Filestream input = Null  ;  6 Binaryreader reader = Null  ;  7       Byte [] Buffer = Null  ;  8   9      Try  10   {  11 Input = New  Filestream (file, filemode. Open, fileaccess. Read, fileshare. readwrite );  12 Reader = New  Binaryreader (input );  13   }  14       Catch  (Exception)  15  {  16 Reader = Null  ;  17   }  18       Finally  19   {  20           If (Reader! = Null  )  21   {  22 Buffer = reader. readbytes (( Int  ) Input. Length );  23   Reader. Close ();  24   }  25   }  26   27       Return  Buffer;  28 }
Reconstruction suggestions

This code is from The Decompilation result of a real exe. I publishCommunitySo far, no one has been able to give my expected views or suggestions.

In fact, this code is not about syntax, encoding style, or exception handling. Veteran should be able to quickly realize the true intention of this Code-read the byte array of the file and return the MD5 hash value of this byte array.

However, when reading the object's byte array, the author compiled a "byte [] _ openfile (string file)" method. On the surface, it looks good and powerful. The author is really eager to read the byte array of files.

You can say that the "byte [] _ openfile (string file)" method is not necessary at all! If you want to disagree, read the following link: http://msdn.microsoft.com/zh-cn/library/3k7ax020 (V = vs.100). aspx.

Some people say that. Net monkeys are all mentally handicapped. Because the. NET Framework encapsulates too many things, these monkeys have a poor understanding of the underlying layer. On the other hand, while increasing productivity, it is tolerable for some people to understand their internal implementations. As long as they can make good use of the framework we provide, they are good monkeys!

The counterargument is that many Java monkeys are unable to accept some logic of the Java language. Why is Java monkeys always advocating that they have various open-source projects and frameworks that can be used? In fact, they also want to steal some laziness. Why do they need to write it by themselves if it is more convenient? Let's look back. Why are JVM-based new languages such as Scala emerging? It is ironic that the generic designer of Java is also the author of scala. Scala is born because the old man cannot bear the inconvenience caused by Java.

Are you sure you want to read the above link? What do you think about the platform's contention? What are your opinions on technological development? Do you have confidence in your code? Can you take responsibility for each line of code you write?

Here, I will not post my own reconstruction results. If you are interested, you can reply in the comments.

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.