ข้ามไปที่เนื้อหาหลัก

เหตุผลที่ทำไมภาษาโปรแกรมมิ่ง D ถึงเป็นตัวเลือกที่ดีสำหรับการพัฒนา

ผมได้ไปอ่านบทความ 5 reasons the D programming language is a great choice for development เจอประเด็นน่าสนใจสองสามประเด็นดังนี้

ชนิดข้อมูลพื้นฐานภาษา D

ชนิดข้อมูลพื้นฐานภาษา D
KeywordDefault Initializer (.init)Description
void-ไม่มีชนิดข้อมูล
boolfalseค่าบูลีน (boolean value)
byte0signed 8 bits
ubyte0unsigned 8 bits
short0signed 16 bits
ushort0unsigned 16 bits
int0signed 32 bits
uint0unsigned 32 bits
long0Lsigned 64 bits
ulong0Lunsigned 64 bits
cent0signed 128 bits (reserved for future use)
ucent0unsigned 128 bits (reserved for future use)
floatfloat.nan32 bit floating point
doubledouble.nan64 bit floating point
realreal.nanlargest FP size implemented in hardwareImplementation Note: 80 bits for x86 CPUs or double size, whichever is larger
ifloatfloat.nan*1.0iimaginary float
idoubledouble.nan*1.0iimaginary double
irealreal.nan*1.0iimaginary real
cfloatfloat.nan+float.nan*1.0ia complex number of two float values
cdoubledouble.nan+double.nan*1.0icomplex double
crealreal.nan+real.nan*1.0icomplex real
char0xFFunsigned 8 bit (UTF-8 code unit)
wchar0xFFFFunsigned 16 bit (UTF-16 code unit)
dchar0x0000FFFFunsigned 32 bit (UTF-32 code unit)
อธิบาย
Boolean: จะให้ค่า true และ false
Signed type: ชนิดข้อมูลนี้สามารถมีค่าได้ทั้งจำนวนเต็มบวกและจำนวนเต็มลบ
Unsigned type: มีค่าจำนวนเต็มบวก
Floating point: มีค่าเป็นจำนวนจริง
Complex number type: ชนิดที่สามารถแทน complex numbers ของคณิตศาสตร์

การประกาศชนิดข้อมูลในภาษา D

สามารถประกาศได้ตามหลัก
type identifier;

ประกาศเป็นข้อมูลชนิด int หรือจำนวนเต็ม
รูปแบบ
int ตัวแปร;
ตัวอย่าง
int a,b,c=6;


ประกาศเป็น float หรือจำนวนจริง
รูปแบบ
float ตัวแปร;
ตัวอย่าง
float d,e;
ประกาศเป็นข้อมูลชนิดสตริง
รูปแบบ
string ตัวแปร;
ตัวอย่าง
string text = "Hello";

ประกาศชนิดข้อมูลแบบ auto
รูปแบบ
auto ตัวแปร;
ตัวอย่าง
import std.stdio;

void main()
{
 int a,b;
 a = 5;
 b = 6;
 auto c = a+b;
 writeln(c);
}
ผลลัพธ์
11

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

โมดูลในภาษา D

สวัสดีผู้อ่านทุกท่านครับ ในการเขียนโปรแกรม บางโปรแกรมมีความซับซ้อนสูงหรือบางครั้งอาจใช้โค้ดเหมือนกัน จึงแยกโค้ดนั้นออกเป็นโมดูล แล้ว import รวมกลับมาในอีกครั้งนึ่ง แล้วคอมไพเลอร์ออกมาเป็นไฟล์เดียว

จัดการ Package และ Build โปรแกรมภาษา D ด้วย dub

dub เป็นเครื่องมือสำหรับใช้สร้างจัดการ Package และ Build โปรแกรมหรือไลบรารีต่าง ๆ ในภาษาดี (D lang)

เรียกใช้ไลบารีภาษา C ในภาษา D

สวัสดีผู้อ่านทุกท่านครับ หลังจากที่ผมย้ายมาเขียนภาษา D แล้วได้ซักระยะหนึ่ง ผมอยากเรียกใช้ไลบารีภาษา C ในภาษา D สามารถเรียกใช้งานได้ดังนี้ครับ