Last active
October 19, 2015 09:21
-
-
Save eyeplum/26e56e90779cd572a549 to your computer and use it in GitHub Desktop.
A talk about WWDC15 at Liulishuo House-warming Party
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Trying to build a Rust version here | |
extern crate rustc_serialize; | |
use std::io; | |
use std::env; | |
use std::path::Path; | |
use std::fs::File; | |
use std::io::Read; | |
use std::vec; | |
use std::io::Write; | |
use rustc_serialize::json::{self, ToJson, Json}; | |
pub fn read_slides(name: &str) { | |
let path = Path::new(name); | |
let display = path.display(); | |
let mut file = File::open(&path).unwrap(); | |
let mut contents = &mut String::new(); | |
file.read_to_string(contents); | |
let json = match Json::from_str(&contents) { | |
Ok(s) => s, | |
Err(why) => panic!("{}", why), | |
}; | |
let array = json.as_array().unwrap(); | |
let len = array.len(); | |
for i in 0..len { | |
let ref slide = array[i]; | |
let ref title = slide["title"]; | |
let bullet_points = slide["bullet_points"].as_array().unwrap(); | |
println!("{} ({})", title, bullet_points.len()); | |
} | |
} | |
fn main() { | |
if let Some(arg1) = env::args().nth(1) { | |
let json = read_slides(&arg1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: set softtabstop=2 : | |
// | |
// Usage | |
// `swiftc lumiere.swift` | |
// `./lumiere slides.json` | |
// | |
import Foundation | |
let Version = "0.1" | |
struct Slide | |
{ | |
let title: String | |
let bulletPoints: [String] | |
} | |
let kSlideTitleKey = "title" | |
let kSlideBulletPointKey = "bullet_points" | |
func loadSlides(fileURL: NSURL) -> [Slide]? | |
{ | |
if let slidesData = NSData(contentsOfURL: fileURL) | |
{ | |
do { | |
if let slidesJSON = try NSJSONSerialization.JSONObjectWithData(slidesData, options: []) as? [[String:AnyObject]] | |
{ | |
var slides: [Slide] = [] | |
for (index, slideJSON) in slidesJSON.enumerate() | |
{ | |
if let title = slideJSON[kSlideTitleKey] as? String | |
{ | |
let slideTitle = "\(title) [\(index + 1)/\(slideJSON.count + 1)]" | |
let slide = Slide(title: slideTitle, bulletPoints: slideJSON[kSlideBulletPointKey] as! [String]) | |
slides.append(slide) | |
} | |
} | |
return slides | |
} | |
} | |
catch { | |
print("Invalid slides data.") | |
} | |
} | |
return nil | |
} | |
func startDisplayLoop(slides: [Slide]) | |
{ | |
print("Bonjour! ಠ_ರೃ ") | |
print("Je suis Lumière, your personal projector.") | |
print("Press enter to start.") | |
print("") | |
var finished = false | |
var slideIndex = 0 | |
var bulletPointIndex: Int? = nil | |
while !finished | |
{ | |
NSFileHandle.fileHandleWithStandardInput().availableData | |
if slideIndex < slides.count | |
{ | |
let slide = slides[slideIndex] | |
if let bIndex = bulletPointIndex | |
{ | |
if bulletPointIndex < slide.bulletPoints.count | |
{ | |
print(" > \(slide.bulletPoints[bIndex])") | |
++bulletPointIndex! | |
} | |
else | |
{ | |
bulletPointIndex = nil | |
++slideIndex | |
} | |
} | |
else | |
{ | |
print(">>> \(slide.title)") | |
bulletPointIndex = 0 | |
} | |
} | |
else | |
{ | |
print("All slides have been displayed.") | |
print("Thank you for using Lumière.") | |
print("Au revoir! ಠ_ರೃ \n") | |
finished = true | |
} | |
} | |
} | |
let args = NSProcessInfo.processInfo().arguments | |
if let slidesFilePath = args.last | |
{ | |
let slidesFileURL = NSURL(fileURLWithPath: slidesFilePath) | |
if let slides = loadSlides(slidesFileURL) | |
{ | |
print("Lumière v\(Version) has successfully loaded '\(slidesFilePath)'.") | |
print("") | |
startDisplayLoop(slides) | |
} | |
else | |
{ | |
print("Failed to load slides.") | |
} | |
} | |
else | |
{ | |
print("Usage: player file") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"title" : "Behind 'App Thinning'", | |
"bullet_points" : [ | |
"let appThinning: BlackMagic = appSlicing + onDemandResources + bitcode", | |
" App Slicing: [[32-bit, 64-bit], [@2x, @3x], [OpenGL.shader, Metal.shader], ...]", | |
" ODR: Up to 4GB resources on server, download if needed", | |
" Bitcode: Submitting LLVM IR to App Store", | |
"WTF is LLVM IR?", | |
"HC SVNT DRACONES! ( 'HERE BE DRAGONS' in Latin )", | |
"The LLVM Compiler Infrastructure", | |
"To compile ObjC running on iPhone 6, for instance:", | |
" let llvm_objc: Compiler = clang: FrontEnd + bitcode: LLVMIR + backEnd: arm64", | |
"For an other instance, to compile Swift running on OS X:", | |
" let llvm_swift: Compiler = swiftc: FrontEnd + bitcode: LLVMIR + backEnd: x86_64", | |
"LLVM IR is the core of LLVM", | |
" It abstracts away details of both the programming language and the target", | |
" It's 'the common language'", | |
"One Lang to Rule Them All!", | |
"Meh, so what?", | |
"If you have a really crappy but cheap CPU...", | |
"And you want to ship the first iteration of the product ASAP...", | |
"Then after you make a lot of $, you want to upgrade the CPU in the next iteration...", | |
"Yes, it's the iPhone.", | |
"'The original iPhone used what was basically an off-the-shelf Samsung DVD player’s processor.'", | |
"$ARCHS = 'armv7 arm64 i386 x86_64'", | |
"No more thinking in $ARCHS,", | |
"thinking in IR.", | |
"Another product comming with a crappy CPU in the 1st iteration:", | |
"WATCH", | |
"'...It(Bitcode) will be mandatory for all watchOS apps...' (WWDC15 Session 102)", | |
"No more recompling to adopt the new CPU", | |
"class-dump /Applications/Photos.app/Contents/MacOS/Photos", | |
" UXViewController", | |
" UXNavigationController", | |
" UXView", | |
" UXCollectionView", | |
" ...", | |
"UXKit! Dude!", | |
"Bitcode + UXKit -> iOS Apps Running on OS X ?", | |
"That's why Apple hired Chris Lattner!", | |
"See also: Edge Cases #124, March 05, 2015", | |
" On bitcode for software distribution" | |
] | |
}, | |
{ | |
"title" : "Subjective-Swift", | |
"bullet_points" : [ | |
"Opinion: Objective-C is more reasonable than Swift, as of today.", | |
"Opinion: But Swift matters, a lot.", | |
"Try to compile a project you've written a year ago:", | |
" clang: Yooooo, build succeeded!", | |
" swiftc: WTF is this 💩 ?", | |
"Code Completion:", | |
" ObjC: fast and accurate", | |
" Swift: slow and SourceKit crash", | |
"Write a library:", | |
" ObjC:", | |
" Input: C/C++/ObjC code", | |
" Output: dynamic linked or static library", | |
" Swift:", | |
" Input: Swift/ObjC code, C code(limited support before Swift2)", | |
" Output: dynamic linked library", | |
"ObjC is getting better:", | |
" Nullability", | |
" Simple Generics", | |
" Not just a language feature,", | |
" but also the APIs. (WWDC15 Session 202)", | |
"The new ResearchKit is written in ObjC", | |
"Why Swift matters?", | |
" Swift is safe by default", | |
" Sometimes 'objc_msgSend' is not fast enough (WWDC15 Session 412)", | |
" All methods in ObjC are virtual functions in the concept of C++", | |
" It's mandatory in ObjC and cannot be changed", | |
" the 'final' keyword can make a function non-virtual in Swift", | |
" Objects (OOP) is easy to be abused", | |
" Swift provides possibilities for a better programming mindset", | |
" Functional Programming", | |
" Or even newer things (WWDC15 Session 408)", | |
" ObjC sits on top of the C Programming Language, Swift is lower level", | |
" If you have to do things like supporting SIMD in ObjC", | |
" you are actually coding in C. (see 'simd.h')", | |
" if you do it in Swift, 'import simd' just works", | |
" Swift is a safer and a potentially faster system programming language", | |
" compared to C", | |
" Swift will be open source", | |
" No ';' required in Swift", | |
"See also: The Rust Programming Language" | |
] | |
}, | |
{ | |
"title" : "The Cocoa community in SF", | |
"bullet_points" : [ | |
"The NeXTEVNT in Cartoon Art Museum", | |
" Hosted by longtime Objective-C hacker(26 yrs), Pixarian(22 yrs), Dr. Michael B. Johnson", | |
"James Dempsey and the Breakpoints", | |
" James worked for Apple for 15 years", | |
" Worked on iOS, Aperture, and OS X 10.5-10.7", | |
" Album: Backtrace", | |
"WWDC Keynote Lineup", | |
"AltConf", | |
" AltConf Streaming of WWDC Content Cancelled" | |
] | |
} | |
] |
extern crate rustc_serialize;
extern crate term_painter;
use std::env;
use std::io::prelude::*;
use std::fs::File;
use std::fmt;
use rustc_serialize::json;
use term_painter::ToStyle;
use term_painter::Color::*;
#[derive(RustcDecodable, RustcEncodable)]
pub struct Slide {
title: String,
bullet_points: Vec<String>,
}
impl fmt::Debug for Slide {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "title: {}, bullet_points: {:?}", self.title, self.bullet_points)
}
}
fn enter_to_go () {
let mut stdin = std::io::stdin();
let mut buffer = String::new();
stdin.read_line(&mut buffer).unwrap();
}
fn read_slides (path: &str) {
let mut file = File::open(path).unwrap();
let mut contents: Vec<u8> = Vec::new();
file.read_to_end(&mut contents).unwrap();
let filestr = String::from_utf8(contents).unwrap();
let slides: Vec<Slide> = json::decode(&filestr).unwrap();
fn print_yellow(str: &str) {
println!("{}", Yellow.paint(str));
}
print_yellow("Bonjour! ಠ_ರೃ ");
print_yellow("Je suis Lumière, your personal projector.");
print_yellow("Press enter to start.\n");
for i in 0..slides.len() {
let ref slide = slides[i];
println!(">>> {} [{}/{}]", Green.paint(&slide.title), i + 1, slides.len());
enter_to_go();
for point in &slide.bullet_points {
println!("> {}", point);
enter_to_go();
}
}
print_yellow("All slides have been displayed.");
print_yellow("Thank you for using Lumière.");
print_yellow("Au revoir! ಠ_ರೃ \n");
}
fn main () {
if let Some(file) = env::args().nth(1) {
read_slides(&file);
}
}
终于搞清楚那个错误的原因了,main 里面是不能 return 的, 而 try!
会 return Error
, see try!, 所以总是出错. 😂
至于去掉双引号的问题没搞明白,不过现在的结果是没有双引号的 💤 @eyeplum
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
❤️ for
see also: The Rust Programming Language