By mk Founder on Tag: Development, Python
Development

หลังจากพัฒนากันมาอย่างยาวนาน Python 3.0 หรือที่รู้จักกันในชื่อ Python 3000 ก็เสร็จสมบูรณ์แล้ว

Guido van Rossum ผู้สร้างภาษา Python บอกว่า Python 3.0 นี้จงใจพัฒนาให้ "เข้ากันไม่ได้" (incompatible) กับเวอร์ชันก่อน (2.6 และสาย 2.x) ด้วยเหตุผลด้านโครงสร้างของภาษา รายการเปลี่ยนแปลงแบบคร่าวๆ มีดังนี้

  • ที่ชัดเจนมากคือเปลี่ยน print จากเดิมเป็น statement กลายมาเป็นฟังก์ชัน

เดิม: print "The answer is", 22
ใหม่: print("The answer is", 2
2)

เดิม: print x
ใหม่: print (x)

  • เปลี่ยนชนิดของตัวแปรที่คืนค่าออกมาในบางกรณี จากเดิมใช้ list เปลี่ยนมาเป็น view หรือ iterator แทน
  • ปรับค่าของการเปรียบเทียบ comparison operators (<, <=, >=, >) ในบางกรณีจะคืนค่า TypeError จากเดิมที่คืน False
  • เปลี่ยนชื่อตัวแปรชนิด long เป็น int ดังนั้นจะเหลือตัวแปรชนิดจำนวนเพียงอย่างเดียวคือ int
  • ปรับปรุงวิธีการเก็บข้อมูลของตัวแปรชนิดข้อความขนานใหญ่ เปลี่ยนมาใช้ Unicode ทั้งหมด ตัวแปรที่เก็บข้อความใช้ str ส่วนตัวแปรที่เก็บข้อมูล (data) คือ bytes และเอาสองชนิดนี้มาผสมกันไม่ได้ (เวอร์ชันก่อนทำได้) ต้องสั่ง encode/decode ก่อนเสมอ
  • ไม่สามารถใช้ u"...." เพื่อให้เข้ารหัสข้อมูลเป็น Unicode ได้อีกแล้ว
  • as กับ with กลายเป็นคำสงวน
  • เลิกใช้ <> สำหรับ "ไม่เท่ากับ"​ ต่อไปจะใชช้ != เพียงอย่างเดียว
  • อย่างอื่นๆ ดูใน What's New in Python 3.0 ละเอียดมาก

การทดสอบเบื้องต้นของทีมพัฒนา Python เองพบว่า Python 3.0 ทำงานได้ช้ากว่า Python 2.5 อยู่ประมาณ 10% โดยเฉลี่ย ซึ่งเป็นเพราะตัวโครงสร้างภาษามีการเปลี่ยนแปลงค่อนข้างเยอะ และเรื่องประสิทธิภาพจะค่อยๆ ถูกแก้ไขใน Python 3.x รุ่นถัดๆ ไปในอนาคต

ส่วนคำแนะนำสำหรับคนที่ต้องการพอร์ตโค้ดเดิมมาเป็น Python 3.0 คือให้พอร์ตจาก 2.x รุ่นใดก็ตามให้ทำงานบน 2.6 ให้ได้ก่อน และใช้เครื่องมือที่มีให้อย่าง "2to3" ช่วยแปลงโค้ด

ตอนนี้ Python 3.0 มีให้ดาวน์โหลดแล้วบนลินุกซ์ (เป็นซอร์สโค้ดไปคอมไพล์เอง) และวินโดวส์ (ติดตั้งได้เลย)​ ทั้งแบบ 32 และ 64 บิต ส่วนเวอร์ชันของดิสโทรก็ต้องรอกันหน่อยตามสูตรครับ อีกไม่นานคงมีพวก PPA ออกมาสำหรับ Ubuntu

ที่มา - Python 3.0 Release

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand

อีกอย่างที่แก้เยอะคือ dictionary ครับ

ตอนนี้ Ubuntu มีแพกเกจ python-3.0 ซึ่งยังเป็นรุ่น rc1 อยู่ คงต้องรออีกสักหน่อย ถึงจะออกรุ่นตัวจริง

เคยเข้าไปอ่านในบล็อกของ Guido van Rossum ครับ เขาบอกว่าไม่ควรเอา 3.0 ไปใช้ในงานดับ production ควรรอ 3.1 หรือ 3.2 ดีกว่า ในระหว่างนี้ให้ใช้ 2.6 ไปก่อน เพราะมันคอยเตือนว่าตรงไหนควรแก้ให้เข้ากันได้กับ 3.x

โดยส่วนตัว ผมจะย้ายก็ต่อเมื่อโมดูลที่ใช้อยู่ย้ายไปอยู่ 3.x จนครบก่อน

BioLawCom.De

khajochi Thu, 04/12/2008 - 20:37

อืม .. ไม่ compatible กับรุ่นเดิมแถมช้าขึ้นอีก .. ต้องคิดหนักขึ้นหน่อยเวลาจะเอามาใช้แล้วเนี่ย

---
Khajochi Blog : It's not a Bug ... It's a Feature

bossalove Thu, 04/12/2008 - 21:28

เพิ่งอ่าน tutorial ภาษา python แล้วก็ลง 2.6 ไปเมื่อวานนี้เอง สิ่งที่เพิ่งอ่านกำลังจะถูกโละ -___-"

ไม่ต้องโละครับ เพราะมันก็ยังเป็น Python เหมือนเดิม syntax กับ module เหมือนเดิมเกือบหมด incompatible ไม่ได้หมายความว่าต้องเขียนโค้ดใหม่หมด แต่ต้องตรวจสอบโค้ดใหม่หมด เท่าที่เคยลอง ผมต้องแก้โค้ดไม่ถึง 5% เพราะไม่ค่อยได้ใช้จุดที่เขาเปลี่ยน

อีกอย่าง 2.6 กับ 3.0 มันก็เกือบ ๆ จะ compatible กันด้วยครับ เพราะ 2.6 ทำมาเพื่อรองรับการก้าวข้ามจาก 2.x เป็น 3.x

BioLawCom.De

Solotov Fri, 05/12/2008 - 01:09

แล้วผมมีหนังสือ Beginning python ของ Apress อยู่(edition แรก) version python ในหนังสือก็ 2.4 ยังงี้นี่ยังไงดีครับ ยังพออ่านตามหนังสือได้ไหมครับ.. หรือทิ้งเลย..

cwt Fri, 05/12/2008 - 01:15

In reply to by Solotov

อ่านได้ครับ ตาม concept แล้วยังเหมือนกันครับ กว่า 3.1 3.2 จะออกมาก็อีกซักพักใหญ่ๆ ครับ เขียนแบบ 2.4 ไปก่อนแล้วลองเอาไป run ใน 2.6 ดูว่ามันฟ้องอะไรตรงไหนครับก็ค่อยไปแก้ตรงนั้น

lew Fri, 05/12/2008 - 01:26

In reply to by Solotov

กว่าที่ซอฟต์แวร์โอเพนซอร์สจะย้ายตัวเองไปใช้ Python 3 กันเยอะๆ น่าจะหลักปีเหมือนกันครับ ไม่ต้องรีบมาก

LewCPE

veer Fri, 05/12/2008 - 15:46

ดูหน้าเขียนขึ้นอีกมาก ... แต่ขี้เกียจ port code เก่ามากมายเหมือนกัน แต่ก็คงคุ้มล่ะ ไม่ได้เปลี่ยนกันบ่อยๆ