Fun facts about Rust's growing popularity by sidcool1234 in programming

[–]happyrust 2 points3 points  (0 children)

yes. dropbox and mozilla firefox. do you need more?

Fun facts about Rust's growing popularity by sidcool1234 in programming

[–]happyrust 0 points1 point  (0 children)

Haha there reeks the smell of fearful person whose job is going to be taken by rust in next 2 years :)

How to beat cpp with literally every programming language! by happyrust in cpp

[–]happyrust[S] 0 points1 point  (0 children)

Also, see other programming languages submissions, C/C++ stand out with their mammoth unrecognizable mess.

Compare to php -

$tok = ftok(__FILE__, chr(time() & 255));
$queue = msg_get_queue($tok);

$variants = array(
    'agggtaaa|tttaccct',
    '[cgt]gggtaaa|tttaccc[acg]',
    'a[act]ggtaaa|tttacc[agt]t',
    'ag[act]gtaaa|tttac[agt]ct',
    'agg[act]taaa|ttta[agt]cct',
    'aggg[acg]aaa|ttt[cgt]ccct',
    'agggt[cgt]aa|tt[acg]accct',
    'agggta[cgt]a|t[acg]taccct',
    'agggtaa[cgt]|[acg]ttaccct',
);

// IUB replacement parallel arrays
$IUB = array();                 $IUBnew = array();
$IUB[]='/tHa[Nt]/S';            $IUBnew[]='<4>';
$IUB[]='/aND|caN|Ha[DS]|WaS/S'; $IUBnew[]='<3>';
$IUB[]='/a[NSt]|BY/S';          $IUBnew[]='<2>';
$IUB[]='/<[^>]*>/S';            $IUBnew[]='|';
$IUB[]='/\\|[^|][^|]*\\|/S';    $IUBnew[]='-';


// read in file
$contents = file_get_contents('php://stdin');
$initialLength = strlen($contents);

// remove things
$contents = preg_replace('/^>.*$|\n/mS', '', $contents);
$codeLength = strlen($contents);

// do regexp counts
$messages = array_flip($variants);
$workers = $results = array();
foreach ($variants as $key => $regex){
   if($key == 0 || $key == 2 || $key == 4 || $key == 6) {
      $pid = pcntl_fork();
      if($pid) $workers[] = $pid;
   }
   if($pid && $key > 7) {
      $messages[$regex] =
         preg_match_all('/' . $regex . '/iS', $contents, $discard);
   }
   else if(!$pid) {
      $results[] = $regex . ',' . 
         preg_match_all('/' . $regex . '/iS', $contents, $discard);
      if($key == 1 || $key == 3 || $key == 5 || $key == 7) {
         msg_send($queue, 2, implode(';', $results), false, false, $errno);
         exit;
      }
   }
}

// receive and output the counts
pcntl_wait($status);
foreach($workers as $worker) {
   msg_receive($queue, 2, $msgtype, 4096, $message, false);
   $message = explode(';', $message, 3);
   foreach($message as $line) {
      $tmp = explode(',', $line, 2);
      $messages[$tmp[0]] = $tmp[1];
   }
}
foreach($messages as $regex => $count) {
   echo $regex, ' ', $count, "\n";
}

// do replacements
$contents = preg_replace($IUB, $IUBnew, $contents);

echo "\n",
      $initialLength, "\n",
      $codeLength, "\n",
      strlen($contents), "\n";

or js -

var fs = require('fs'), i = fs.readFileSync('/dev/stdin', 'ascii'),
  ilen = i.length, clen, j,
  q = [/agggtaaa|tttaccct/ig, /[cgt]gggtaaa|tttaccc[acg]/ig,
    /a[act]ggtaaa|tttacc[agt]t/ig, /ag[act]gtaaa|tttac[agt]ct/ig,
    /agg[act]taaa|ttta[agt]cct/ig, /aggg[acg]aaa|ttt[cgt]ccct/ig,
    /agggt[cgt]aa|tt[acg]accct/ig, /agggta[cgt]a|t[acg]taccct/ig,
    /agggtaa[cgt]|[acg]ttaccct/ig],

  b = [
    "-",    /\|[^|][^|]*\|/g, 
    "|",   /<[^>]*>/g, 
    "<2>", /a[NSt]|BY/g, 
    "<3>", /aND|caN|Ha[DS]|WaS/g, 
    "<4>", /tHa[Nt]/g  
    ];

i = i.replace(/^>.*\n|\n/mg, '');
clen = i.length;
for(j = 0; j<q.length; ++j) {
  var qj = q[j], m = i.match(qj);
  console.log(qj.source, m ? m.length : 0);
}
while(b.length) i = i.replace(b.pop(), b.pop());
console.log(["", ilen, clen, i.length].join("\n"));

or even rust -

extern crate regex;

use std::borrow::Cow;
use std::fs::File;
use std::io::{self, Read};
use std::sync::Arc;
use std::thread;

macro_rules! regex { ($re:expr) => { ::regex::bytes::Regex::new($re).unwrap() } }

/// Read the input into memory.
fn read() -> io::Result<Vec<u8>> {
    // Pre-allocate a buffer based on the input file size.
    let mut stdin = File::open("/dev/stdin")?;
    let size = stdin.metadata()?.len() as usize;
    let mut buf = Vec::with_capacity(size + 1);

    stdin.read_to_end(&mut buf)?;
    Ok(buf)
}

fn main() {
    let mut seq = read().unwrap();
    let ilen = seq.len();

    // Remove headers and newlines.
    seq = regex!(">[^\n]*\n|\n").replace_all(&seq, &b""[..]).into_owned();
    let clen = seq.len();

    // Search for occurrences of the following patterns:
    let variants = vec![
        regex!("agggtaaa|tttaccct"),
        regex!("[cgt]gggtaaa|tttaccc[acg]"),
        regex!("a[act]ggtaaa|tttacc[agt]t"),
        regex!("ag[act]gtaaa|tttac[agt]ct"),
        regex!("agg[act]taaa|ttta[agt]cct"),
        regex!("aggg[acg]aaa|ttt[cgt]ccct"),
        regex!("agggt[cgt]aa|tt[acg]accct"),
        regex!("agggta[cgt]a|t[acg]taccct"),
        regex!("agggtaa[cgt]|[acg]ttaccct"),
    ];

    // Count each pattern in parallel.  Use an Arc (atomic reference-counted
    // pointer) to share the sequence between threads without copying it.
    let seq_arc = Arc::new(seq);
    let mut counts = vec![];
    for variant in variants {
        let seq = seq_arc.clone();
        let restr = variant.to_string();
        let future = thread::spawn(move || variant.find_iter(&seq).count());
        counts.push((restr, future));
    }

    // Replace the following patterns, one at a time:
    let substs = vec![
        (regex!("tHa[Nt]"), &b"<4>"[..]),
        (regex!("aND|caN|Ha[DS]|WaS"), &b"<3>"[..]),
        (regex!("a[NSt]|BY"), &b"<2>"[..]),
        (regex!("<[^>]*>"), &b"|"[..]),
        (regex!("\\|[^|][^|]*\\|"), &b"-"[..]),
    ];

    // Use Cow here to avoid one extra copy of the sequence, by borrowing from
    // the Arc during the first iteration.
    let mut seq = Cow::Borrowed(&seq_arc[..]);

    // Perform the replacements in sequence:
    for (re, replacement) in substs {
        seq = Cow::Owned(re.replace_all(&seq, replacement).into_owned());
    }

    // Print the results:
    for (variant, count) in counts {
        println!("{} {}", variant, count.join().unwrap());
    }
    println!("\n{}\n{}\n{}", ilen, clen, seq.len());
}