代码如何变得不可理解
发布于 2小时前 作者 tulayang 38 次浏览 最后一次编辑是 17分钟前 来自 分享
  (write-string vram "Nim" (make-color Yellow DarkGrey) (pos 25 9))
  (write-string vram  "Expressive. Efficient. Elegant." (make-color Yellow DarkGrey) (pos 25 10))
  
  =>
  
  write_string(vram, "Nim", make_color(Yellow, DarkGrey), (25, 9))
  write_string(vram, "Expressive. Efficient. Elegant.", make_color(Yellow, DarkGrey), (25, 10))
  
  =>

  let attr = make_color(Yellow, DarkGrey)
  write_string(vram, "Nim", attr, (25, 9))
  write_string(vram, "Expressive. Efficient. Elegant.", attr, (25, 10))
  
  |
  
  let attr = make_ioutils_color(Yellow, DarkGrey)
  write_ioutils_string(vram, "Nim", attr, (25, 9))
  write_ioutils_string(vram, "Expressive. Efficient. Elegant.", attr, (25, 10))
  
  => 
  
  let attr = ioutils.makeColor(Yellow, DarkGrey)
  ioutils.writeString(vram, "Nim", attr, (25, 9))
  ioutils.writeString(vram, "Expressive. Efficient. Elegant.", attr, (25, 10))
export function* show_image(ynext, next, req, res) { 
    let image_id = escape_id(req.params.image_id);
    if (equal(image_id, 0)) 
        bad_request(res);
    else {
        let [err, image, comments] = yield get_image_and_comments(image_id, ynext); 
        if (err) 
            server_error(res);
        else {
            send(res, 200, 'OK', {'content-type':'application/json'}, 
                 { image:image, comments:comments });
            yield* next;
        }
    }
}

=>

export function* show_image(ynext, next, req, res) { 
    let image_id = util.escape_id(req.params.image_id);
    if (util.equal(image_id, 0)) 
        res.bad_request();
    else {
        let [err, image, comments] = yield image.get_one_and_comments(image_id, ynext); 
        if (err) 
            res.server_error();
        else {
            res.send(200, 'OK', {'content-type':'application/json'}, 
                     { image:image, comments:comments });
            yield* next;
        }
    }
}

=>

export function* showImage(ynext, next, request, response) { 
    let imageId = util.escapeId(req.params.image_id);
    if (imageId === 0) {
        response.writeHead(400);
        response.end();
    } else {
        let [err, image, comments] = yield image.getOneAndComments(imageId, ynext); 
        if (err) {
            response.writeHead(500);
            response.end();
        } else {
            response.writeHead(200, 'OK', {'content-type':'application/json'});
            response.end(JSON.stringify({ image:image, comments:comments }));
            yield* next;
        }
    }
}

=>

var queryGetOneAndComments = `
select
    userid,
    username,
    basename,
    joindate
from  images
where image_id = ?;

select
    c.comment_id,
    c.pubdate,
    c.content,
    c.userid,
    c.username,
    t.userid    as to_userid,
    t.username  as to_username
from      comments    as c
left join comment_tos as t on c.comment_id = t.comment_id
where c.image_id = ?`;

export function* showImage(ynext, next, request, response) { 
    let imageId = util.escapeId(req.params.image_id);
    if (imageId === 0) {
        response.writeHead(400);
        response.end();
    } else {
        let [err, image, comments] = yield pool.query(
            queryGetOneAndComments, 
            [imageId, imageId], 
            ynext
        );
        if (err) {
            response.writeHead(500);
            response.end();
        } else {
            response.writeHead(200, 'OK', {'content-type':'application/json'});
            response.end(JSON.stringify({ image:image, comments:comments }));
            yield* next;
        }
    }
}
回到顶部