duangsuse::Echo
711 subscribers
4.24K photos
127 videos
583 files
6.44K links
import this:
美而不丑、明而不暗、短而不凡、长而不乱,扁平不宽,读而后码,行之天下,勿托地上天国。
异常勿吞,难过勿过,叹一真理。效率是很重要,盲目最是低效。
简明是可靠的先验,不是可靠的祭品。
知其变,守其恒,为天下式;穷其变,知不穷,得地上势。知变守恒却穷变知新,我认真理,我不认真。

技术相干订阅~
另外有 throws 闲杂频道 @dsuset
转载频道 @dsusep
极小可能会有批评zf的消息 如有不适可退出
suse小站(面向运气编程): https://WOJS.org/#/
Download Telegram
Forwarded from 任桑 今天开始做魔王
所以抄个别的语言的代码套在py上,我是否可以理解为你既不熟悉scheme也不熟悉py呢,不然你干嘛要抄
Forwarded from dnaugsuz
只是习惯了,好比我之前写过 Haskell,所以喜欢用 for x in xs: 一些,谁能因此断言 for 一定是 Haskell way (forM_) 或者 x/xs 一定是 Python way?
Forwarded from dnaugsuz
其实我上面喷的单纯是那个必须 explicit 的 self 参数,在 Rust 这样“多范式”的语言里往往才是这样(事实上,Rust 是有 impl 的,不需要显式写 self 参数)

以及一个 str.join 的小问题——别的语言都是 iter.join,Python 给搞个 str.join,还是“面向对象”语言

给人感觉设计上不够坚定,把 re module 不和 built-in str 结合在一起可以认为是“工程”的,可 a join xs 这种命名方法完全是过分模拟自然语言语序,虽然 Python 是很早就诞生的“脚本语言”所以有些问题很正常,我觉得作者的设计水平还是感觉一般
Forwarded from LightQuantum
import this
Forwarded from dnaugsuz
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Forwarded from dnaugsuz
看来 Python 的 core devs 还是一群文艺青年,我还以为导入这个模块可以提供 this 字面名呢
Forwarded from dnaugsuz
Complex is better than complicated.
是啊,可是 self 哪里比 implicit this (实际上有点像作用域策略) 更 *不* complicated 的了?
duangsuse::Echo
上等讨论是交流观点,中等讨论是谈论事件,低等讨论是评判个人。 ——浅谈价值表达
第三次,我居然一句话没说(叮~counter+1),麻木了吗?还是我本来就不应该考虑那些事情?
我……真的不能写应用? 🤔
刚才我看到了 https://azul.rs/ 的 button counter 示例程序,默写下? #code

//use ...

struct Counter {
count: i32
}
impl Layout for Counter {
fn layout(self: Counter, _info: &LayoutInfo) -> Dom {
let label = Label::new(format!("{}", self.count)).dom();
let button = Button::new("+1")
.clicked(Callback(onIncClicked));
Dom::div()
.add(label).add(button)
}
fun onIncClicked(self: Counter) -> ScreenUpdate {
self.count += 1
Redraw
}
}


第二次
extern create azul;
use azul::{ prelude::*, label::Label, button::Button }

struct AppState {
counter: usize
}
impl Layout for AppState {
fun layout(&self, _info: LayoutInfo<Self>) -> Dom<Self> {
let label = Label::new(format!("{}", self.counter));
let btn_inc = Button::new("+1").handle("click", Callback(onIncClicked));
Dom::new().with_child(label).with_child(btn_inc);
}
fun onIncClicked(&mut self) -> ScreenUpdate {
self.counter += 1
Redraw
}
}
extern create azul;
use azul::{ prelude::*, widget::{ label::Label, button::Button } };

struct DataModel {
counter: usize
}
impl Layout for DataModel {
fn layout(&self, _info: LayoutInfo<DataModel>): Dom<DataModel> {
let label = Label::new(format!("{}", self.counter));
let btn_inc = Button::with_label("+1").add_action(On::MouseUp, Callback(onIncClicked));
Dom::div().with_child(label).with_child(btn_inc)
}
fn onIncClicked(info: EventInfo<DataModel>) -> ScreenUpdate {
info.state.data.counter += 1
Redraw
}
}
duangsuse::Echo
extern create azul; use azul::{ prelude::*, widget::{ label::Label, button::Button } }; struct DataModel { counter: usize } impl Layout for DataModel { fn layout(&self, _info: LayoutInfo<DataModel>): Dom<DataModel> { let label = Label::new(format!("{}"…
extern crate azul;

use azul::{prelude::*, widgets::{label::Label, button::Button}};

struct DataModel {
counter: usize,
}

impl Layout for DataModel {
fn layout(&self, _info: LayoutInfo<Self>) -> Dom<Self> {
let label = Label::new(format!("{}", self.counter)).dom();
let button = Button::with_label("Update counter").dom()
.with_callback(On::MouseUp, Callback(update_counter));

Dom::div()
.with_child(label)
.with_child(button)
}
}

fn update_counter(event: CallbackInfo<DataModel>) -> UpdateScreen {
event.state.data.counter += 1;
Redraw
}

fn main() {
let mut app = App::new(DataModel { counter: 0 }, AppConfig::default()).unwrap();
let window = app.create_window(WindowCreateOptions::default(), css::native()).unwrap();
app.run(window).unwrap();
}

这是真实代码

fun main() {
let mut app = App::create(DataModel { counter = 0 }).unwrap();
let win_main = Window::create(WindowOptions::default(), css:native).unwrap();
app.run(win_main).unwrap()
}


fun main() {
let mut app = App::new(DataModel { counter = 0 }, AppOptions::default()).unwrap();
let win_main = app.create_window(WindowOptions::default(), css::native).unwrap();
app.run(win_main).unwrap();
}

unwrap()
几乎写到手软,记得当初信 Rust 教的时候,对这个名词相当困扰,不知道它是 Option<T> 上的一个操作……
Forwarded from dnaugsuz
啊,很老很老的 Intel x86 架构手册,一般只有编译器后端的工程师才会看的那种
Forwarded from dnaugsuz
对我来说,如果一个人有学姐的名号,就是要向请教的晚辈主动提供些信息的
现在不少的大佬,带着权威的性格,却一个字也不会给提问的人透露