Tags:
Rust

Rust เป็นภาษาโปรแกรมภาษาใหม่ที่พัฒนาโดย Mozilla โดยมุ่งเป้าว่าต้องการเป็นภาษาสำหรับงานประมวลผลที่ทำงานพร้อมๆ กัน (concurrency) และทำงานบนระบบขนาดใหญ่ ออกแบบมาไม่ให้มีปัญหาด้านหน่วยความจำอย่าง buffer overflow

การใช้งานจะเป็นระบบคอมไพล์ ตัว syntax ของภาษาจะคล้ายกับ C/C++ คือเป็นภาษาที่ใช้วงเล็บปีกกา {} และประกาศตัวแปรแบบ static

ตอนนี้สถานะของ Rust ยังเป็นเวอร์ชัน 0.1 รุ่นทดสอบ ความสามารถและประสิทธิภาพยังไม่สมบูรณ์มากนัก ตัวซอร์สโค้ดของเครื่องมือต่างๆ เปิดเป็นโอเพนซอร์สด้วยสัญญาอนุญาตแบบ MIT (โค้ดอยู่บน GitHub)

ตัวอย่างโค้ดในภาษา Rust

use std;
import std::io;

fn main() {
    for i in [1, 2, 3] {
        io::println(#fmt("hello %d\n", i));
    }
}

คุณสมบัติอื่นๆ ของภาษา Rust ก็ขอยกมาจากเว็บต้นทางเลยนะครับ

  • Compilation model batch, ahead-of-time, C/C++ compatible
  • Type system static, structural-algebraic, with metadata
  • Type inference yes, only local variables
  • Generic types yes, only simple, non-turing-complete substitution
  • Concurrency isolated tasks, message passing
  • Unique pointers move semantics, no races or sharing
  • Memory safety no buffer overflow, use before init, NULL or free()
  • Immutability immutable by default, mutability is the special case
  • Garbage collection optional, per-task, only "shared" types
  • Error handling isolated tasks, unrecoverable unwinding
  • Text utf8 strings, ucs4 characters
  • Tier 1 platforms Linux, OSX, Windows
  • Developers Mozilla
  • License MIT

เป้าหมายสุดท้ายของ Rust คือเป็นภาษาที่มาแทน C++ ของฝั่ง Mozilla และในอนาคตเราอาจได้เห็นโค้ดบางส่วนของ Firefox ถูกแปลงเป็น Rust แทน C++

ที่มา - ExtremeTech

Comments

By: caznova
Windows PhoneAndroidWindows
caznova's blog
on 26/01/12 15:49 #377436 toggle
caznova's picture

มี <br> ด้วย อิอิ


Acaz

By: neizod
ContributorTraineeIn Love
neizod's blog
on 26/01/12 15:56 #377439 toggle
neizod's picture

มันย่อซะจนแอบงงนะเนี่ย fn เอง fmt เอย

By: mr_tawan
ContributoriPhoneAndroidWindows
mr_tawan's blog
on 26/01/12 17:42 #377471 Reply to:377439 toggle
mr_tawan's picture

มันจะไม่ได้มาเป็น C/C++ ก็เพราะว่าภาษามันอ่านยากนี่ล่ะ


By: nolykk
ContributoriPhoneAndroidUbuntu
nolykk's blog
on 26/01/12 16:09 #377442 toggle
nolykk's picture

ชื่อไม่เป็นมงคลเลย Rust -> ถูกทิ้งให้สนิมขึ้น ?? ฮาๆครับ


twitter.com/djnoly

By: multiplex
multiplex's blog
on 26/01/12 16:15 #377443 toggle
multiplex's picture

ดีนะที่ไม่ใช่ io::prtln(#fmt("hello %d\n", i));

By: arth
iPhone
arth's blog
on 26/01/12 16:23 #377445 Reply to:377443 toggle
arth's picture

ดีนะที่ไม่ใช่ io::prtln(#fmt("hlo %d\n", i));

By: HudchewMan
ContributorAndroidWindows
HudchewMan's blog
on 27/01/12 1:12 #377573 Reply to:377445 toggle
HudchewMan's picture

ดีนะที่ไม่ใช่ io::ptl(#fmt("hl %d\n", i));


~ จุดยืนของทุกคนคือส้นเท้า : HudchewMan's Diary | TH LG Optimus Black ~

By: IceDagger
IceDagger's blog
on 26/01/12 17:24 #377461 toggle
IceDagger's picture

จะเพิ่มภาษาอะไรกันมาอีกเยอะแยะใช้ syntax แบบ C/C++ ที่มีอยู่แล้วมันลำบากมากหรือไงนะ แทนที่จะเอาเวลาไป improve C++ compiler ยังจะดีซะกว่า เบื่อพวกโปรแกรมเมอร์ก้อตรงนี้แหละ ไม่อยากเห็นศาสดาภาษาโปรแกรมมิ่งเพิ่มแล้ว เบื่อ - -

By: narate
AndroidUbuntuWindowsIn Love
narate's blog
on 26/01/12 20:19 #377500 Reply to:377461 toggle
narate's picture

ตัวเลือกเยอะย่อมดีกว่า เขาไม่ได้บังคับใช้น่ะ


แฟนผมชื่อ คอมพิวเตอร์

By: Thaina
Windows
Thaina's blog
on 26/01/12 20:29 #377503 Reply to:377461 toggle
Thaina's picture

ก็ C++ มันยุ่งยากไร้สาระเกินความจำเป็นน่ะครับ และบางทีก็ไม่เหมาะกับบางงาน

แถมไลบรารี่เก่าๆก็รกไปหมด Legacy ขยะก็มีเพียบ ไล่โค้ดก็ยาก

C++0x ก็พยายามแก้ แต่ก็ได้แค่นั้น


My Blog

By: oAOEo
iPhoneAndroidSymbian
oAOEo's blog
on 30/01/12 7:55 #378230 Reply to:377503 toggle
oAOEo's picture

แต่ผมว่าเพราะความยุ่งยากนั่นแหละทำให้มันยืนหยัดอยู่จนทุกวันนี้

By: wrongite
wrongite's blog
on 26/01/12 21:02 #377512 toggle
wrongite's picture

เหมือน C/C++ แต่เห็นแล้วคิดถึง Python นิดๆ

By: prophecyx
iPhone
prophecyx's blog
on 27/01/12 10:06 #377619 toggle
prophecyx's picture

ทำให้มันใช้ integrate กับ C/C++ compiler ด้วยนะ จะได้นัวแบบ Objective-C


.... คิดก็ให้รู้ว่าคิด ....

By: ultimateohm
ContributorAndroidRed HatWindows
ultimateohm's blog
on 27/01/12 20:22 #377705 toggle
ultimateohm's picture

มีตัวอย่างแบบที่ได้อานิสงส์จากการประมวลแบบขนาน เช่น bitonic sort ไหมครับ แล้วมันได้ประโยชน์จาก GPGPU ด้วยไหม


int a[256];

void bitonicSort(int lo, int cnt, int dir)
{
    int k;
    if (cnt >1)
    {
        k=cnt/2;
        bitonicSort(lo, k, (1 >0)); bitonicSort(lo+k, k, (0 >1));
        bitonicMerge(lo, cnt, dir);
    }
}

void bitonicMerge(int lo, int cnt, int dir)
{
    int k,i;
    if (cnt >1)
    {
        k=cnt/2;
        for (i=lo; i< lo+k; i++) swapifneed(i, i+k, dir); 
        bitonicMerge(lo, k, dir); bitonicMerge(lo+k, k, dir); 
    }
}

void swapifneed(int i, int j, int dir)
{
    int h;
    if (dir==(a[i] >a[j]))
    {
        h=a[i];
        a[i]=a[j];
        a[j]=h;
    }
}

ตรงที่เป็นบรรทัดเดียว แต่มีมากกว่า 1 statement คือ ทำขนานกันได้


aka ohmohm

By: GooEng
ContributorWindows PhoneAndroidUbuntu
GooEng's blog
on 27/01/12 23:14 #377841 Reply to:377705 toggle
GooEng's picture

ดูมีประโยชน์ แต่ต้องใช้สมาธิเวลาอ่าน ไม่งั้นจะงงว่า statement เดียวกัน เวลาตาลาย


คำตอบของข้า คือ ประกาศิต

By: ultimateohm
ContributorAndroidRed HatWindows
ultimateohm's blog
on 29/01/12 14:34 #378156 toggle
ultimateohm's picture

Rust มันแตก tasks แบบนี้หรืิอเปล่า และมี Ports and channels ทำหน้าที่คล้ายๆ IPC


aka ohmohm

By: ultimateohm
ContributorAndroidRed HatWindows
ultimateohm's blog
on 30/03/12 21:00 #402231 toggle
ultimateohm's picture

Rust version 0.2 มาแล้ว


aka ohmohm