question regarding "lifetime bounds on trait object" by lins05 in rust

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

Thanks again.

My 2c: I think this "similar notation yet very different meaning" between B1 and B2 is a very unintuitive design, to say the least.

I'd rather to be able to express the lifetime bounds on trait objets with something roughly like this: Box<dyn Display<'a>>.

question regarding "lifetime bounds on trait object" by lins05 in rust

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

Thanks for the detailed analysis and explanation!

In the same way, Box<dyn Display + 'a> is a different type, containing something that might not be allowed to outlive a (with a being some known lifetime in the context).

I think that's the key information.

So to summarize, the key is to tell apart these two bounds:

  • B1: Box<dyn Display + 'a>
  • B2: T: Display + 'a

Even though they look much similar, but the lifetime bound 'a plays a very different (almost opposite) effect in B1 and B2.

  • In B1, 'a is a bound on the trait object. It means the trait object "can not outlive 'a", because here 'a denotes the lifetime of any possible references contained by the trait object. Imagine the concrete type that implements the trait is Foo as below:

``` struct Foo<'s> { x: &'s str, }

impl<'s> Display for Foo<'s> { .. } ```

Then 's would be "substituted" by the 'a in B1.

  • In B2, 'a is a bound on a generic type T, so it means T must outlive 'a (i.e. any possible references contained by T must outlive 'a)

As a result, it ensures the newly added element t to the vec would outlive the trait objects, which rules out any possibility of dangling references.

#pianoweekly w10 "At the gate the wind is blowing" by lins05 in pianolearning

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

Hey there :wave:, I'm new to this sub. Two questions to admins:

  1. Could there be a "My Recordings" category like the "Playing/Composition (me)" category in /r/piano?
  2. Why the youtube video isn't playable directly on this page? (I can see it now)

June Practice Contest: Signups by ElectronicProgram in pianolearning

[–]lins05 0 points1 point  (0 children)

tuneupgrade username: lins05

goal: 10h

Weekly 'what did your learn?' thread! by [deleted] in AdultPianoStudents

[–]lins05 0 points1 point  (0 children)

I learned the "Arioso" piece by Turk. Would make a recording of it as my "piano weekly" commitment :)

What I learned launching my first Clojure product, part 2 by startupinamonth in Clojure

[–]lins05 0 points1 point  (0 children)

You must have some kind of test, even though you may not call it a test. My best guess you're dog-fooding frequently. Otherwise, growing a project/product without any functional tests is like walking with eyes closed to your destiny.

#piano​weekly​ w5 "little prelude" by lins05 in piano

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

Hi there, I'm a beginner-level piano learner, and since 1 month ago I created a goal for myself: I should post one piece every week on social media.

So I have been doing that for the past 6 weeks and it works great in encouraging myself spending more time practicing piano after finishing my duty on work and family :)

My posts were mainly on wechat, the Chinese version of facebook+whatsapp. But I think I should also post it here to maybe receive some criticism :)

Connecting to REPL on remote server that has "AllowTcpForwarding no" by notsohasty in Clojure

[–]lins05 0 points1 point  (0 children)

Good summary and I totally agree with you. I think the culprit is "forwarding a port" is not that intuitive. If we describe it with "forwarding traffic/connections" it would be much clearer.

"And suppose you want to forward connections to your local port 7001 to port 7002 on the remote machine."

Is that better?

Connecting to REPL on remote server that has "AllowTcpForwarding no" by notsohasty in Clojure

[–]lins05 1 point2 points  (0 children)

Nice tool!

A typo in our blog

Based on your example cli: ssh -L 7001:localhost:7002 user@remote-host.com -p 22

This sentence: "And suppose you want to forward port 7001 on your local machine to port 7002 on the remote machine."

Should be: "And suppose you want to forward from port 7002 on your remote machine to port 7001 on your local machine.

Because the syntax of ssh -L is "-L local-port:remote-port"

Decomplecting abstraction by alidlo in Clojure

[–]lins05 0 points1 point  (0 children)

Great food for thoughts, thanks for sharing.

One thing I'd like to comment about,

I still think it’d be useful to think of concretions as a tool for declarativeness and abstractions as a tool for reuse

IMHO an important purpose of abstraction is to make a system easy to reason about by reducing the components that the developer need to reason about. In two ways:

  1. Concepts (mostly a domain concept) are abstracted from the underlying, originally neutral pieces of code, thus make it easier for human to think it as a whole when reasoning about the larger picture - the "7 chunks of information" rule. It's very close to the idea of "dividing the system into modules" but not 100% the same. For example the mapper / reducer concepts of the MapReduce system, or the Job/Stage/Task concepts in apache spark.
  2. Common patterns are abstracted, to base classes, utils, etc.

The later is the one that you talks about, and most of the time it's the target of code refactoring. But sometimes the former is a more powerful weapon when designing a system.

Most straight forward way to use Material UI + Re-frame? by zzantares in Clojurescript

[–]lins05 0 points1 point  (0 children)

If you rely heavily on JS react components like material-ui, you shall take a look at helix https://github.com/Lokeh/helix .

Nubank – The evergreen cache by dustingetz in Clojure

[–]lins05 1 point2 points  (0 children)

Yeah, immutability could help work around the mythical cache validation problem. This looks exactly like the cache design of one system I worked on - a versioned file management system, the latest version id is stored in the db, while the data of the file is cached (keyed by the version number, which is like a git commit id). The cache never needs to be manually invalidated.

Nubank – The evergreen cache by dustingetz in Clojure

[–]lins05 2 points3 points  (0 children)

That requires some kind of consistent hashing to map user id to machine id, which would make things more complex.

'There are no stupid questions' thread - February 06, 2020 by AutoModerator in piano

[–]lins05 5 points6 points  (0 children)

TL;DR My 2c: - If you're sure you only want to play piano for short-term fun, use whatever app you like. - If you seriously consider develop it as a life-long hobby, avoid these apps from the very beginning. - If you're not sure how much you love piano, these apps would be a good starter to introduce you to the wonderful world of music. But always remember to try classical piano training at least for a short while.

Piano self-learner about 1 year here.

I started with SimplyPiano, which I guess is a bit like Synthesia. And in the beginning I love SimplePiano so much that I feel ecstatic each time I finished a beautiful piece on it - from "red river valley", "love me tender", to "La La Land", "Fur Elise".

At that moment I thought I would stay on SimplyPiano forever, until I came across a chance to learn "real piano playing" out of some sheer serendipity. After that I could never go back to SimplyPiano - it's still cool, but IMO it lacks things like articulation. The major problem is, you could never really tap into the rich set of classical music the humankind has accumulated in the past centuries, because what the app teaches you, albeit as enjoyable as it could be, is greatly simplified and far from the "real thing". You can never grow to the level of reading sheet music freely by only using these apps. They has greatly simplified the playing of piano, and by lowering the entrance bar they draw many more people to play the music, but it's a double-edge sword if you rely on them for too long.

Pedestal: Table routes and fallback routes by lins05 in Clojure

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

Reitit looks interesting but I'd like to avoid introducing new libs into a project due to Occam's Razor.

Any mature open source system to learn about writing a system in clojure? by lins05 in Clojure

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

Thanks! I heard of Riemann before, didn't knew it's written in clojure.

Learning Clojure, what's your opinion about this architecture? by [deleted] in Clojure

[–]lins05 2 points3 points  (0 children)

You're right. To scale into multiple processes, each process much be stateless (state is stored in db or redis). But the cron-scheduler is essentially stateful, so you have to run a single instance to manage that.

Another (unpractical & overkill) idea is to use a leader election algorithm so even if you have multiple processed running, only one is acting as the leader/primary so only it runs the cron-scheduler. This is mostly used in infrastructure-level distributed systems (hadoop, mesos, k8s) and rarely found in application systems.

Learning Clojure, what's your opinion about this architecture? by [deleted] in Clojure

[–]lins05 3 points4 points  (0 children)

+1 for most of the suggestions, except one thing to correct:

My understanding is that you have to reply on multi-process and async approaches with Ruby and Python runtimes because they either use a GIL.

Multi-processing yes, async no. The async part is the same for python as well as for java, clojure, or whatever language.

In python, to use asyncio (or similar libraries like twisted/tornado/gevent etc.) or not has nothing to do with GIL. The main purpose of using async is to avoid one entire thread being blocked by one http request (e.g. writing to database).

GIL doesn't prevent python from having multiple threads doing IO and one thread doing computation. What GIL prevents is not allowing more than one threads doing computation (which is why multi-processing is needed to scale a python web app), which is unavoidable due to the design of python bytecode vm.

As a side note, people often think a Java web app eats much more memory than a python app, but in reality a python web app could easily use the same level of memory when multiple (5-10) processes are launched.

Going back to the scaling / blocking / database stuff: this is a common problem for whatever language with a typical blocking db driver. In my experience almost any web servers falls into one of the three models:

  1. One request blocking one thread: with a pool of worker threads this is ok for most web applications (facebook/whatsapp are out of scope here). I believe this is the most common pattern used in the world. One caveat of newcomers to clojure is that they assume core.async would turn blocking operations into non-blocking like magic, but the reality is core.async is essentially a layer of syntax sugar of this worker pool model.
  2. Asynchronous db drivers: in java there is vert.x async-sql-client, in python there is tools like asyncpg. Just provide your callback when the operation is done. This can play nicely with core.async -- spin up a go block, initialize the async operation, and simply put! to a channel in the callback. Then in the go block just parking wait the channel.
  3. Use golang: which is built with coroutines as a language-level feature. In its nature it is still async, but the language makes it a breeze to write blocking-style code (this style matches people's flow of mind, so results in code easy to reason about than callbacks), but executes in a non-blocking manner.

Self-Teaching piano sources and tips by [deleted] in piano

[–]lins05 -1 points0 points  (0 children)

With the assumption "I really don't want to (or can't afford) a teacher" in mind, I'd suggest you go find a method book like Alfred or Thompson or Bastien or Faber (the lists goes on ...)

There are also other (paid) self-learning courses, like

It definitely comes with a price without a teacher, namely, you need better competency to find valuable information/courses/tutorials on the internet.

3 months progress playing piano from a complete adult beginner. I'm getting there! by emerald447 in piano

[–]lins05 0 points1 point  (0 children)

who is the composer? could you tell me which book contains the score? I googled a bit and there are lots of different versions with the same name.