Hiển thị các bài đăng có nhãn coding. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn coding. Hiển thị tất cả bài đăng

[Python] Pythonic, Pythoneer, Pythonist, Pythonista ?!


First of all,

If you have coded in Python, you must know these terms: PYTHONIC, PYTHONIST, PYTHONEER and PYTHONISTA... So what is the meaning of those terms ?!
Pythonic simply means something like "idiomatic Python".
Pythoneer and Pythonista - of course - are people who love Python. For me, Pythonista are programmers who are real loyal fans of Python-the-language. Pythoneer - in my view - are the ones that always think and create new things using Python, they seems to be the ones who are likely the leaders talking about Python programming and stuffs... Well, that's just my own opinion.

But that's not the main content of this blog entry. If this is the first time you've coded in Python and you want to learn more about this language, I think you should read those 2 articles below. Those articles are about the style of coding of PYTHONISTAs and the meaning of PYTHONIC. When I first learnt Python, I was so glad that I had read those articles:

Know more about the meaning of Pythonic:
http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0

English version for "Code like a Pythonista: Idiomatic Python": http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

(For my dear Vietnamese friends, there is a VNese version too)
http://www.vithon.org/2007/07/28/l%E1%BA%ADp-trinh-nh%C6%B0-m%E1%BB%99t-pythonista:-thanh-ng%E1%BB%AF-python

Give thanks to those articles' author/blogger. I love those articles !
Enjoy your time reading, everyone !

[Coding] How to code ?!

For me, source codes are just something really small. I usually share all my codes. Therefore, I like open-source. People can use codes and if there are bugs, they contact the programmer who codes.
As a result, in my view, source code is just a means of studying programming.

This blog entry is not about coding any specific language or source code. This one, I'll share some tips to have a "clean" code.


  • The first one is about the header of your code. Try to add a header for your file. That header will give other people about your information:

Example:
/* author: BinhMinh
* DateModified:
* Content:
* License (optional) :
* Reference:
* Language:
*/

  • Second rule: Always remember "TAB" in coding. A code with tab in newline is always prefered.

Ex1:  int func1 (int param1, int param2) {
                     return 0;
        }
Ex2:  int fun1 (int param1, int param2) {
         return 0;
        }
I prefer the Ex1 code.


  • Third rule: Try making the name of variable easy to understand. Some people will code with variable like: _1, _2, a, b, c... Of course you will have difficulty in understand your own code later, cause you don't even know those variables do what ?! So make sure you have variables like: count, testingId,...
  • Fourth: Try commenting as possible as you can. Those comments will be really useful for reusing codes.
  • Fifth: Add documents for your function. If you have seen my Python blog entries, you will see that I always add document for all my functions. Or you can see example in the entry [Java] Math Parser. Not all programmers do this one. But it will help you a lot when you do big projects.
  • Sixth: For Java, C,.. use blockscope in conditional expressions no matter what.
Ex: if (A) {
            B
     }
     else {
           C
    }

  • Seventh: Try to seperate your codes into independent objects. You can use these objects for other projects.
  • Last one: If tired of coding, relax about 15 minutes and then back. Maybe in relaxing time, you will have more ideas for your code.
I just try to have a blog entry about ways of coding cause I've seen so many of my friends' code not clean, not reusable or not just understandable. 
Have fun in reading everyone !

     

[Geometry] Simple code for geometry

You guys can use all this codes in this blog. If you have questions, just comment or send emails to [email protected] (I suggest sending emails).I will help you with my best.

Coding - somehow - makes things simple. I'm doing a project which is the same with Paint in Windows OS. The first step, I must realize the type of geometry. This codes below will do that:
I code in C++

// author: BinhMinh


#include <iostream>
#include <math.h>
#define e 1e-6
using namespace std;

struct Point{
      double x;
      double y;
};

struct Vector{
       double x;
       double y;
};

struct Line{
      double a;
      double b;
      double c;
};

double abs(double x){
       if(x<0) return -x;
       return x;
}

//Area of triangle ABC, Newton
double Area(Point A, Point B, Point C){
       double t1 = A.x*B.y + B.x*C.y + C.x*A.y;
       double t2 = A.y*B.x + B.y*C.x + C.y*A.x;
       if(t1>t2) return (t1-t2)/2.0;
       return (t2-t1)/2.0;
}

//Distance between 2 Points
double Dist(Point A, Point B){
       return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}

//Distance between Point X and line d(AB)
double DistPointLine(Point C, Point A, Point B){
       double s = Area(C, A, B);
       double a = Dist(A, B);
       return 2.0*s/a;
}

//Make Vector AB
void MakeVector(Point A, Point B, Vector &AB){
     AB.x = B.x-A.x;
     AB.y = B.y - A.y;
}

//dot vector a and vector b
double Dot(Vector a, Vector b){
       return a.x*b.x + a.y*b.y;
}

//dot vector AB and vector CD
double Dot(Point A, Point B, Point C, Point D){
       Vector AB, CD;
       MakeVector(A, B, AB);
       MakeVector(C, D, CD);
       return Dot(AB, CD);
}

//Minimum distance between Point C and segment AB
double DistPointSegment(Point C, Point A, Point B){
     double m;
     if(Dot(A,B,A,C)<=0 || Dot(B,C,B,A)<=0){
         return min(Dist(A,C), Dist(B,C));
     }
     else return DistPointLine(C, A, B);
}

//Area of Polygon, N>=3
double AreaOfPolygon(int N, Point P[]){
       double s = 0.0;
       for(int i = 2; i<N ; i++) s+=Area(P[0], P[i-1], P[i]);
       return s;
}

//Make Line a*x+b*y=c
void MakeLine(Point A, Point B, Line &d){
     d.a = B.y - A.y;
     d.b = A.x - B.x;
     d.c = A.x*d.a + A.y*d.b;
}

//doubleersection of 2 lines
int Intersection2Line(Line d1, Line d2, Point &P){
    double delta = d1.a*d2.b - d2.a*d1.b;
    if(abs(delta)<e) return 0; // No doubleersection
    P.x = (d1.c*d2.b - d2.c*d1.b)/delta;
    P.y = (d1.a*d2.c - d2.a*d1.c)/delta;
    return 1;  
}

//doubleersection of 2 Segments AB and CD
//AB = A + (B-A)t = A + ut
//CD = C + (D-C)t' = C + vt'
//t = (C-A).vT / u.vT
int Intersection2Segment(Point A, Point B, Point C, Point D, Point &P){
    Vector u, v, vT, AC;
    MakeVector(A, B, u);
    MakeVector(C, D, v);
    MakeVector(A, C, AC);
    vT.x = -v.y;
    vT.y = v.x;
    if (abs(Dot(u, vT))<e) return 0;
    double t = Dot(AC, vT) / Dot(u, vT);
    if (t<0 || t>1) return 0;
    P.x = A.x + u.x*t;
    P.y = A.y + u.y*t;
}

//Circle from 3 Points
void Bisector(Point A, Point B, Line &d){
     double x, y;
     x = (A.x + B.x)/2.0;
     y = (A.y + B.y)/2.0;
     d.a = B.x - A.x;
     d.b = B.y - A.y;
     d.c = d.a*x + d.b*y;
}
int Circle(Point A, Point B, Point C, Point &I, double R){
     Line d1, d2;
     Bisector(A, B, d1);
     Bisector(A, C, d2);
     if( Intersection2Line(d1, d2, I) == 0 ) return 0;
     R = Dist(I, A);
     return 1;
}

[Android] First feeling ...

First of all,
I must say that I'm a fan of iOS development.
The first time I've worked with Android, I was so disappointed. The Android Emulator runs tooooo slowww, and sometimes I have trouble with the Heap and Stack running processes.

Some people will think Android is an OS. That's totally wrong !
Android is an open-platform with Apache2.0 license. Because it's "open", now, you can see, there is Android everywhere, from mobile to household stuffs (like washing machine, InternetTV,...). So I'm curious about Android. That's the reason why I came to Android. :))

There are 4 things that I experienced in coding Android:

  • You should code GUI with the XML file if you want a clean and well-structured GUI for your apps.
  • Once running the emulator, do not try to close it if you want to test your code later. The emulator takes so much time initializing.
  • Learning JavaSE soon, if you want to make an Android app.
  • Should not use Android 4.0. I realize it's a mistake using Android 4.0 cause it has the least documents and there are some components in Android4 which are not "open-source".
So that is just my feeling when I first "met" the big-guy-called-Android.
I will have an Android tutorial for coding in the next blog entry. Hope everyone likes it !