When you program in Java, you use types. You use int-s, floats, classes and so on.
We have seen a Class can be a nice place to put a struct. In Java, you often need to do a cast from a type to another. This is very common, and no one has trouble. In Smalltalk, the Virtual Machine only understands objects. If we execute 1+2 the VM of Smalltalk search the method + in the object 1, instance of the Number class. If Smalltalk do not found the method, will throw a Exception at Runtime
Exceptions are defined in ANSI Smalltalk. Some Smalltalk implementation may not have Exception, but can raise Errors.
The language-designers say type are userful, because the compiler can produce efficient code if it knows the type we are using (the sum of an two numbers is fast if they are integer and not float!).
Someone thinks type are userful to human-programmers, but in my own opinion, after two years of Smalltalk programming, it is not-so-true.
So, let's start to see how to program without type (and without casts...or other magic powers...)
เมื่อคุณโปรแกรมใน Java , คุณใช้ประเภท คุณใช้ int-s , ลอย , ชั้นเรียนและอื่น ๆ .
เราได้เห็นชั้นสามารถเป็นสถานที่ที่ดีที่จะใส่ซอฟต์แวร์ . ใน Java , คุณมักจะต้องทำเฝือกจากชนิดอื่น นี้เป็นปกติมาก และไม่เคยมีปัญหา ในเพิร์ล , เครื่องเสมือนเพียงเข้าใจวัตถุ ถ้าเราเรียก 1 2 VM ค้นหา Smalltalk วิธีการวัตถุ 1ตัวอย่างของจำนวนห้อง ถ้า Smalltalk ไม่พบวิธีที่จะโยนข้อยกเว้นที่ runtime
ยกเว้นที่กำหนดไว้ในมาตรฐาน ANSI Smalltalk . บางคนใช้ Smalltalk อาจไม่มีข้อยกเว้น แต่สามารถสร้างข้อผิดพลาด
ภาษานักออกแบบกล่าวว่า userful ชนิด ,เพราะคอมไพเลอร์สามารถผลิตที่มีประสิทธิภาพรหัส ถ้ามันรู้ชนิดที่เราใช้ ( ผลรวมของตัวเลขสองได้อย่างรวดเร็วหากพวกเขาเป็นจำนวนเต็มและลอย )
บางคนคิดว่าเป็นประเภท userful โปรแกรมเมอร์ของมนุษย์ แต่ในความคิดของผม หลังจากสองปีของการเขียนโปรแกรม Smalltalk , มันไม่ได้เป็นงั้นจริง
ดังนั้นขอเริ่มต้นเพื่อดูวิธีการโปรแกรมโดยไม่ต้องพิมพ์ ( และไม่ลอก . . . . . . . หรือพลังวิเศษอื่น ๆ . . . . . . . )
การแปล กรุณารอสักครู่..
