Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Python mu Java mı?
VS
© Ahmet Erkan ÇELİK Haziran 2012
JAVA TEMİZDİR!
 Örneğin şöyle bir JAVA sınıfını
public class Employee
{
private String myEmployeeName;
private int myTaxDeductions = 1;
private String myMaritalStatus = "single";
//--------- constructor #1 -------------
public Employee(String EmployeName)
{
this(employeeName, 1);
}
//--------- constructor #2 -------------
public Employee(String EmployeName, int taxDeductions)
{
this(employeeName, taxDeductions, "single");
}
//--------- constructor #3 -------------
public Employee(String EmployeName,
int taxDeductions,
String maritalStatus)
{
this.employeeName = employeeName;
this.taxDeductions = taxDeductions;
this.maritalStatus = maritalStatus;
}
}
PYTHON DAHA TEMİZDİR
 Python ile yazacak olursak
class Employee():
def __init__(self,
employeeName
, taxDeductions=1
, maritalStatus="single"
):
self.employeeName = employeeName
self.taxDeductions = taxDeductions
self.maritalStatus = maritalStatus
JAVA Hızlıdır
 projecteuler.net problemlerinden 22. soru:
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing
over five-thousand first names, begin by sorting it into alphabetical order. Then
working out the alphabetical value for each name, multiply this value by its
alphabetical position in the list to obtain a name score.
For example, when the list is sorted into alphabetical order, COLIN, which is worth 3
+ 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a
score of 938 53 = 49714.
What is the total of all the name scores in the file?
JAVA Hızlıdır!
Java ile çözümü
import java.util.Arrays;
import java.lang.StringBuilder;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class euler22
{
public static String readFileAsString(String path) throws IOException
{
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(
new FileReader(path));
String buffer = null;
while((buffer = reader.readLine()) != null)
{
builder.append(buffer);
}
reader.close();
return builder.toString();
}
public static void main(String[] args) throws IOException
{
String[] names = fileAsString("names.txt").replace(""", "").split(",");
int total = 0;
Arrays.sort(names);
for(int i = 0; i < names.length; ++i)
{
int sum = 0;
for(char c : names[i].toCharArray())
{
sum += c - 'A' + 1;
}
total += (i + 1) * sum;
}
System.out.println(total);
}
}
Kod çalışma süresi : ~0.3s
Python Daha hızlıdır!
Python ile çözümü
def main():
names = open("names.txt", "r").read().replace(""", "").split(",")
names.sort()
print sum((i + 1) * sum(ord(c) - ord('A') + 1 for c in n) for i, n in enumerate(names))
if __name__ == "__main__":
main()
Kod çalışma süresi : ~0.05s
Framework Çözümleri
Python Frameworkleri Java Frameworkleri
• Tornado
• Django
• Grok
• Pylons
• TurboGears
• Web2Py
• Zope
• CubicWeb
• Enamel
• GAE Framework
• Gizmo (QP)
• Glashammer
• Karrigell
• Kiss.py
• Nagare
• …
• Tapestry
• Cocoon
• MyFaces
• Spring
• Google Web Toolkit
• Turbine
• Makumba
• Stripes
• JPublish
• JOSSO
• wings
• Strecks
• AribaWeb
• Playframework
• Anvil
• …
Kaynaklar
 http://pythonconquerstheuniverse.wordpress.com
/2009/10/03/python-java-a-side-by-side-
comparison/
 http://codereview.stackexchange.com/questions/1
0997/python-vs-java-runtime-on-euler-22
 http://wiki.python.org/moin/WebFrameworks
 http://java-source.net/open-source/web-
frameworks

More Related Content

Python mu Java mı?

  • 1. Python mu Java mı? VS © Ahmet Erkan ÇELİK Haziran 2012
  • 2. JAVA TEMİZDİR!  Örneğin şöyle bir JAVA sınıfını public class Employee { private String myEmployeeName; private int myTaxDeductions = 1; private String myMaritalStatus = "single"; //--------- constructor #1 ------------- public Employee(String EmployeName) { this(employeeName, 1); } //--------- constructor #2 ------------- public Employee(String EmployeName, int taxDeductions) { this(employeeName, taxDeductions, "single"); } //--------- constructor #3 ------------- public Employee(String EmployeName, int taxDeductions, String maritalStatus) { this.employeeName = employeeName; this.taxDeductions = taxDeductions; this.maritalStatus = maritalStatus; } }
  • 3. PYTHON DAHA TEMİZDİR  Python ile yazacak olursak class Employee(): def __init__(self, employeeName , taxDeductions=1 , maritalStatus="single" ): self.employeeName = employeeName self.taxDeductions = taxDeductions self.maritalStatus = maritalStatus
  • 4. JAVA Hızlıdır  projecteuler.net problemlerinden 22. soru: Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 53 = 49714. What is the total of all the name scores in the file?
  • 5. JAVA Hızlıdır! Java ile çözümü import java.util.Arrays; import java.lang.StringBuilder; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class euler22 { public static String readFileAsString(String path) throws IOException { StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader( new FileReader(path)); String buffer = null; while((buffer = reader.readLine()) != null) { builder.append(buffer); } reader.close(); return builder.toString(); } public static void main(String[] args) throws IOException { String[] names = fileAsString("names.txt").replace(""", "").split(","); int total = 0; Arrays.sort(names); for(int i = 0; i < names.length; ++i) { int sum = 0; for(char c : names[i].toCharArray()) { sum += c - 'A' + 1; } total += (i + 1) * sum; } System.out.println(total); } } Kod çalışma süresi : ~0.3s
  • 6. Python Daha hızlıdır! Python ile çözümü def main(): names = open("names.txt", "r").read().replace(""", "").split(",") names.sort() print sum((i + 1) * sum(ord(c) - ord('A') + 1 for c in n) for i, n in enumerate(names)) if __name__ == "__main__": main() Kod çalışma süresi : ~0.05s
  • 7. Framework Çözümleri Python Frameworkleri Java Frameworkleri • Tornado • Django • Grok • Pylons • TurboGears • Web2Py • Zope • CubicWeb • Enamel • GAE Framework • Gizmo (QP) • Glashammer • Karrigell • Kiss.py • Nagare • … • Tapestry • Cocoon • MyFaces • Spring • Google Web Toolkit • Turbine • Makumba • Stripes • JPublish • JOSSO • wings • Strecks • AribaWeb • Playframework • Anvil • …