[spam][crazy] coding therapy: hello world with structure
Form: A simple statement, such as printing hello world, makes use of multiple elements of structured data, such as a struct or class, to compose its parameters and/or function.
class HelloWorld { public: char const *hello; char const *world; }; void main() { HelloWorld helloworld; helloworld.hello = “hello”; helloworld.world = “world; printf(“%s %s\n”, helloworld.hello, helloworld.world); }
class HelloWorld(object): def __init__(self, hello, world): self.words = (hello, world) def print(self): print(‘ ‘.join(self.words)) if __name__ == ‘__main__’: HelloWorld(‘hello’, ‘world).print()
i havent learned rust yet for becoming-obvious reasons struct HelloWorld { hello: String, world: String } impl HelloWorld { fn print(&self) { println!(“{} {}”, self.hello, self.world); } } fn main() { let helloworld = HelloWorld { hello: “hello”, world: “world” }; helloworld.print(); }
relearning javascript class HelloWorld { constructor(hello, world) { this.words = {“hello”: hello, “world”: world}; } print() { console.log(this.words.hello + ‘ ‘ + this.words.world); } }; (new HelloWorld(‘hello’, ‘world’)).print()
class F: funcs = [repr, print, eval, str, int] words = ‘world house tree brush hello’.split(‘ ‘) F.funcs(1)(F.words[4], F.words[0])
struct particle_t { float pos[4], vel[4], accel[4]; }; void particle_update(particle_t * p, float time) { for (int coord = 0; coord < 4; coord += 1) { pos[coord] += vel[coord] * time; vel[coord] += accel[coord] * time; } }
class HelloWorldNode { public: HelloWorldNode(HelloWorldNode * parent, string data) : parent(parent), data(data) { if (parent) parent.children.add(this); } ~HelloWorldNode() { if (parent) parent.children.erase(this); } void print() { cout << data; for (auto child : children) child.print(); } private: HelloWorldNode * parent; string data; set<HelloWorldNode*> children; }; using HWN = HelloWorldNode; int main() { HWN hello(0, “hello”); HWN space(&hello, “ “); HWN world(&space, “world”); HWN bang(&world, “!”); HWN decorations[] = { HWN(&hello, “\t”), HWN(&world, “~~”), HWN(&bang, “#”) }; hello.print(); }
participants (1)
-
Undescribed Horrific Abuse, One Victim & Survivor of Many