Thursday, August 20, 2015

یکسری وب سایت و ابزار بدرد بخور برای اندروید کارا

آموزشی

  • Context, What Context: این مطلب در رابطه با انواع کانتکست های اندرویده و اینکه از هر کدومشون کجا باید استفاده و کجا نباید استفاده کرد. 
  • Android Material Design Slidenerd Style: آموزش  فوق العاده کاربردی در رابطه با طراحی متریال دیزاین.

ابزارها

  • Android Asset Studio: یه ابزاره حسابیه برای درست کردن انواع آیکون ها مثل آیکن اعلان، اکشن بار، لانچر و ...
  • DP/PX Convertor: تبدیل DP، پیکسل، اینچ و ... به هم
  • App Mirror: مجموعه ای کامل از اپلیکشن های اندرویده که به راحتی قابله دانلود روی مرورگر هست
  • Mocking Bot: یه وب سایت خوب و رایگان برای درست کردن ماک برنامه

کتابخانه ها (Library)

  • ButterKnife: یه کامپونته خیلی خفن که تو همه پروژه ها ازش استفاده می کنم، کارش اینه که ویجت ها (TextView, Button , ...) رو با یه خط انوتیت (Annotate) می شه وارد کرد به اکتیویتی یا فرگمنت، حتما توصیه می کنم یه چک بکنین
  • ASNE: یه کتابخانه کامل برای کار با شبکه های اجتماعی مثل: Twitter, Linkedin, Google Plus, Facebook, Instagram , ...
  • timber: یه لاگر فوق العاده کاربردی نسبت به Log کلاس پیش فرض اندروید، با این کتابخانه می تونید لاگ های دیباگ و ورباس (Timber.d , Timber.v) رو تو نسخه نهایی غیر فعال کنید و لاگ های ارور و هشدار (Timber.e , Timber.w) رو از طریق exception reporter (مثل google analytics) ارسال کنید برای خودتون.
  • Android-Iconics : تو اندروید یکی از سخت ترین کارا اضافه کردن آیکونه، این کتابخونه با استفاده از فونت های آیکونی با جاش این مشکل رو حل کرده.

پلاگین برای اندروید استادیو

  • ParcelableGenerator: برای تولید Parcelable اندروید، کلاس رو بسازید، فیلد ها رو بهش اضافه کنید بعدش کلید میانبر ALT + Insert رو بزنید و گزینه Parcelable رو انتخاب کنید. :D
  • ADB Idea:  یه میانبر خوب برای اجرای دستورات پر کاربرد بر روی گوشی ای که به سیستم وصله، دستوراتی مثل حذف نرم افزار، بستن نرم افزار، پاک کردن کش، و اجرای مجدد نرم افزار
این مجموعه در حال تکمیله اگه شما هم ابزار بدرد بخوری می شناسید معرفی کنید

Monday, June 29, 2015

OpenJDK VS Oracle JDK

مشکلی که همیشه موقع نصب جاوا برام پیش میاد اینه که اوپن JDK رو کارایی بهتری داره و یا اوراکل JDK،  این دفعه مشکل رو با کمی تحقیق حل کردم:

هنریک استال معاون مدیریت اجرایی گروه جاوا تو شرکت اوراکل در این رابطه نوشته (متن به صورت خلاصه ترجمه شده):

این دو بسیار به هم شبیه اند، برای ایجاد نسخه ی اوراکل JDK تنها چند تکه به آن اضافه می کنیم،
به طور مثال:
  •  پلاگین جاوا (اجرا کننده ی Applet ها) و وب استارت (اجرا کننده ی نرم افزار جاوا به صورت یک کلیک)
  • یکسری از کامپوننت های کد بسته دیگر شرکت ها مثل graphics rasterizer و بعضی از فونت های استفاده شده
  • یکسری از کامپوننت های کد باز دیگر شرکت ها مثل Rhino ( راینو: موتور جاوا اسکریپت که به طور کامل با جاوا پیاده سازی شده است و توسط شرکت موزیلا توسعه داده می شود)


در ادامه هنریک نوشته : نیت ما کد باز کردن تمامی قسمت های اوراکل JDK هست به جز قسمت هایی که دارای امکانات تجاری هستند مثل Jrockit Mission Control (ابزاری برای مانیتور کردن و پروفایل کردن نرم افزار های جاوا که هنوز این محصول از طرف اوراکل ارائه نشده) باقی قسمت ها با کامپوننت های متن باز جابه جا خواهند شد.

طبق گفته این دوست عزیز از نظر کارایی تفاوت چندانی نمی کنه که از کدام JDK استفاده کنیم، برای همین من ترجیح می دم از اوپن JDK‌استفاده بکنم که هم کد بازه و هم با یک دستور تو اوبونتو نصب می شه

sudo apt-get install openjdk-8-jdk

Thursday, February 19, 2015

کتابخانه کار با رابط درگاه اینترنتی بانک ملت برای جاوا



برای کار با درگاه بانک ملت یه کتابخانه (یا همون library) با IntelliJ IDEA درست کردم، گفتم اینجا بزارم تا بقیه هم بتونن استفاده کنند.

کار با این کتابخانه خیلی راحته، نمونه کد زیر از متد bpPayRequest بانک ملت استفاده می کنه و در خواست تراکنش رو برای بانک ارسال می کنه. مابقی API های بانک ملت همانند مثال زیر یک متد دارند با یکسری پارامتر های ورودی و خروجی معین شده توسط خود بانک ملت.

IPaymentGateway service = new PaymentGatewayImplService().getPaymentGatewayImplPort();
            String response = service.bpPayRequest(
                    12,
                    "USER NAME",
                    "PASSWORD",
                    mellatBank.getId() ,
                    mellatBank.getPrice(),
                    mellatBank.getLocalDate(),
                    mellatBank.getLocalTime(),
                    "",
                    "response url",
                    0
            );

از این کتابخانه برای سایت آنلاین دارو استفاده کردم
اینم لینک دانلود کتابخانه

Thursday, December 11, 2014

‌Bad Smells in Code


Duplicated Code

If you see the same code structure in more than one place, you can be sure that your program will be better if you find a way to unify them.

Long Method

The object programs that live best and longest are those with short methods.
There is still an overhead to the reader of the code because you have to switch context to see what the sub procedure does. Development environments that allow you to see two methods at once help to eliminate this step, but the real key to making it easy to understand small methods is good naming. If you have a good name for a method you don't need to look at the body.

Large Class

When a class is trying to do too much, it often shows up as too many instance variables. When a class has too many instance variables, duplicated code cannot be far behind.

Long Parameter List

In our early programming days we were taught to pass in as parameters everything needed by a routine. This was understandable because the alternative was global data, and global data is evil and usually painful. Objects change this situation because if you don't have something you need, you can always ask another object to get it for you. Thus with objects you don't pass in everything the method needs; instead you pass enough so that you the method can get to everything it needs.

Divergent Change

Divergent change occurs when one class is commonly changed in different ways for different reasons.

Shotgun Surgery

Shotgun surgery is similar to divergent change but is the opposite. You whiff this when every time you make a kind of change, you have time to make a lot of little changes to a lot of different classes. When the changes are all over the place, they are hard to find, and it's easy to miss an important change.

Feature Envy

The whole point of objects is that they are a technique to package data with the processes used on that data. A classic smell is a method that seems more interested in a class other than the one it actually is in.

Data Clumps

Data items tend to be like children; they enjoy hanging around in groups together. Often you'll see the same three or four data items together in lots of places: fields in a couple of classes, parameters in many method signatures.Bunches of data that hang around together really ought to be made into their own object.

Primitive obsession

You use primitives in the system to pass data, rather than objects, and it gets in the way of understanding the code. Eg. passing arrays everywhere.

Switch Statements

One of the most obvious symptoms of object-oriented code is its comparative lack of switch (or case) statements. The problem with switch statements is essentially that of duplication. Often you find the same switch statement scattered about a program in different places.The object-oriented notion of polymorphism gives you an elegant way to deal with this problem.

Parallel Inheritance Hierarchies

Parallel inheritance hierarchies is really a special case of shotgun surgery. In this case, every time you make a subclass of one class, you also have to make a subclass of another. You can recognize this smell because the prefixes of the class names in one hierarchy are the same as the prefixes in another hierarchy.

Lazy Class

Each class you create costs money to maintain and understand. A class that isn't doing enough to pay for itself should be eliminated. Often this might be a class that used to pay its way but has been downsized with refactoring. Or it might be a class that was added because of changes that were planned but not made. Either way, you let the class die with dignity.

Speculative Generality

You get it when people say, "Oh, I think we need the ability to this kind of thing someday" and thus want all sorts of hooks and special cases to handle things that aren't required. The result often is harder to understand and maintain.

Temporary Field

Sometimes you see an object in which an instance variable is set only in certain circumstances. Such code is difficult to understand, because you expect an object to need all of its variables. Trying to understand why a variable is there when it doesn't seem to be used can drive you nuts.

Message Chains

You see message chains when a client asks one object for another object, which the client then asks for yet another object, which the client then asks for yet another another object, and so on. You may see these as a long line of getThis methods, or as a sequence of temps. Navigating this way means the client is coupled to the structure of the navigation. Any change to the intermediate relationships causes the client to have to change.

Middle Man

One of the prime features of objects is encapsulation—hiding internal details from the rest of the world. Encapsulation often comes with delegation. You ask a director whether she is free for a meeting; she delegates the message to her diary and gives you an answer. All well and good. There is no need to know whether the director uses a diary, an electronic gizmo, or a secretary to keep track of her appointments.
However, this can go too far. You look at a class's interface and find half the methods are delegating to this other class. After a while it is time to use Remove Middle Man and talk to the object that really knows what's going on.

Inappropriate Intimacy

Sometimes classes become far too intimate and spend too much time delving in each others private parts. We may not be prudes when it comes to people, but we think our classes should follow strict, puritan rules.

Data Class

These are classes that have fields, getting and setting methods for the fields, and nothing else. Such classes are dumb data holders and are almost certainly being manipulated in far too much detail by other classes. In early stages these classes may have public fields. If so, you should immediately apply Encapsulate Field before anyone notices.

Refused Bequest

Subclasses get to inherit the methods and data of their parents. But what if they don't want or need what they are given? They are given all these great gifts and pick just a few to play with. The traditional story is that this means the hierarchy is wrong.

Comments

Don't worry, we aren't saying that people shouldn't write comments. In our olfactory analogy, comments aren't a bad smell; indeed they are a sweet smell. The reason we mention comments here is that comments often are used as a deodorant. It's surprising how often you look at thickly commented code and notice that the comments are there because the code is bad. Comments lead us to bad code that has all the rotten whiffs we've discussed in the rest of this chapter.
If you need a comment to explain what a block of code does, try Extract Method. If the method is already extracted but you still need a comment to explain what it does, use Rename Method. If you need to state some rules about the required state of the system, use Introduce Assertion.


Summary of the "Refactoring: Improving the Design of Existing Code"

Saturday, October 4, 2014

Code Refactoring


What Is Refactoring ?

Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. It is a disciplined way to clean up code that minimizes the chances of introducing bugs. In essence when you refactor you are improving the design of the code after it has been written.

Tip: When you find you have to add a feature to a program, and the program's code is not structured in a convenient way to add the feature, first refactor the program to make it easy to add the feature, then add the feature.

The First Step in Refactoring

Whenever I do refactoring, the first step is always the same. I need to build a solid set of tests for that section of code. The tests are essential because even though I follow refactorings structured to avoid most of the opportunities for introducing bugs, I'm still human and still make mistakes. Thus I need solid tests.

Tip: Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

Why Should You Refactor?

 I don't want to proclaim refactoring as the cure for all software ills. It is no "silver bullet." Yet it is a valuable tool, a pair of silver pliers that helps you keep a good grip on your code. Refactoring is a tool that can, and should, be used for several purposes.

Refactoring Helps You Find Bugs

Help in understanding the code also helps me spot bugs. I admit I'm not terribly good at finding bugs. Some people can read a lump of code and see bugs, I cannot. 
However, I find that if I refactor code, I work deeply on understanding what the code does, and I put that new understanding right back into the code. By clarifying the structure of the program, I clarify certain assumptions I've made, to the point at which even I can't avoid spotting the bugs.

It reminds me of a statement Kent Beck often makes about himself, "I'm not a great programmer; I'm just a good programmer with great habits." Refactoring helps me be much more effective at writing robust code.

Refactoring Helps You Program Faster

This sounds counterintuitive. When I talk about refactoring, people can easily see that it improves quality. Improving design, improving readability, reducing bugs, all these improve quality. But doesn't all this reduce the speed of development
I strongly believe that a good design is essential for rapid software development. 

Indeed, the whole point of having a good design is to allow rapid development. Without a good design, you can progress quickly for a while, but soon the poor design starts to slow you down. You spend time finding and fixing bugs instead of adding new function.

Changes take longer as you try to understand the system and find the duplicate code. New features need more coding as you patch over a patch that patches a patch on the original code base. A good design is essential to maintaining speed in software development. Refactoring helps you develop software more rapidly, because it stops the design of the system from decaying. It can even improve a design.

When Should You Refactor

In almost all cases, I'm opposed to setting aside time for refactoring. In my view refactoring is not an activity you set aside time to do. Refactoring is something you do all the time in little bursts. You don't decide to refactor, you refactor because you want to do something else, and refactoring helps you do that other thing.

Refactor When You Need to Fix a Bug

In fixing bugs much of the use of refactoring comes from making code more understandable. As I look at the code trying to understand it, I refactor to help improve my understanding. Often I find that this active process of working with the code helps in finding the bug. One way to look at it is that if you do get a bug report, it's a sign you need refactoring, because the code was not clear enough for you to see there was a bug.

When Shouldn't You Refactor

There are times when you should not refactor at all. The principle example is when you should rewrite from scratch instead. There are times when the existing code is such a mess that although you could refactor it, it would be easier to start from the beginning.
A clear sign of the need to rewrite is when the current code just does not work. You may discover this only by trying to test it and discovering that the code is so full of bugs that you cannot stablilize it.

The other time you should avoid refactoring is when you are close to a deadline. At that point the productivity gain from refactoring would appear after the deadline and thus be too late.


Summary of the "Refactoring: Improving the Design of Existing Code" book