The Perils of Partially Powered Languages - <AUTHOR> http://www.yesodweb.com/blog/2011/08/perils-partially-powered-languages <comment><USER2> I find it a little embarrassing that a blog about a web framework fails to load (though perhaps that's a little unfair considering a HN traffic spike). Especially since I thought one of Yesods main advantages was performance.

For the lazy (pun intended) his Conclusions are:

\- Java-the-language and Java-the-libraries make a number of simple tasks very complicated. \- Therefore, we have a number of helper languages, like XSLT and Ant, to avoid the pain of a pure Java solution. \- However, these tools are all purposely missing some features we'll inevitably need. \- The result will be either missing proper handling of some features, a polyglot that will miss the point of using Java in the first place, or most likely both. \- There are great use cases for non-general-purpose languages, but they should have tight integration with a real language. \- Haskell's flexible syntax and great typing make it very powerful here.

I just spent last weekend putting together a Yesod web app and am very sympathetic to his mantra. Hamlet is a lovely language (valid HTML is valid Hamlet so very easy to pick up) that does one thing well, one thing well, and nothing else. It very easily allows me to go back into Haskell if I need to. The key is that Hamlet is merely syntactic sugar. Ant isn't just syntactic sugar, its far more than that, which makes it different.

<comment><USER3> If Yesod is about performance, it's not showing: [http://www.techempower.com/blog/2013/04/05/frameworks- round-...](http://www.techempower.com/blog/2013/04/05/frameworks-round-2/)

<comment><USER4> Be sure to check community commentary on the implementations that were tested before deriving any conclusions: [http://www.reddit.com/r/haskell/comments/1bqsvi/web_woes_for...](http://www.reddit.com/r/haskell/comments/1bqsvi/web_woes_for_haskell)

<comment><USER5> _For the lazy:_

The reason for Yesod's poor showing in that benchmark was due to a flaw in the implementation of the benchmark. A certain function (newSTDGen) was called repeatedly within each request, even though it should have only been called once; it's a relatively "expensive" function so this had a large impact on the results of the test.

In addition, the Yesod test used TCP sockets to communicate with MySQL while the other frameworks were set to use UNIX sockets. This has also been found to have a non-trivial impact on performance, as discussed in this SO thread:

[http://stackoverflow.com/questions/257433/postgresql-unix- do...](http://stackoverflow.com/questions/257433/postgresql-unix-domain- sockets-vs-tcp-sockets)

<comment><USER6> >A certain function (newSTDGen) was called repeatedly within each request

It is called zero times in the json benchmark, which yesod still did quite poorly on. That is only a factor in the "pull a random thing from the DB" test. I believe the biggest underlying issue was that sessions are enabled, which means transmitting more data (the cookie) as well as doing encryption and HMAC on the cookies. Disabling sessions doubled the performance.

</comment></comment></comment></comment></comment><comment><USER7> I'm glad I read it, because I never would have known about XProc otherwise, but a lot of his specific complaints are moot today. XProc apparently supports directory listing out of the box and there is now a zip module for it. In any case you could extend these tools with your own code if you wanted to continue to use them, they all offer extension points (mostly in Java, sadly, but a directory listing is just a directory listing).

His overall point is not moot but at the same time I'm not all that sympathetic. As you dig deeper and deeper into the XML ecosystem you learn that more and more of it is really only there so that there can be an XML answer for every problem. I doubt many people see the benefits of a comprehensive XML ecosystem (frankly, I doubt that the benefits are all that meaningful) but if you don't see the point then you're engaging in pointless masochism by trying to use it. That he solved his problems by going outside the XML ecosystem suggests that he doesn't really perceive the benefit of it, which makes the whole exercise a little circular. "I like sweets and I don't like vegetables, and I discovered that if I put sugar on my vegetables I like them better than if I don't." Yeah, that's what I'd expect you'd find.

</comment><comment><USER8> I think this article is oh-so-close to making some great points. Using a DSL like XSLT for XML transformation is a _lot_ more productive than in Java.

"Quite simply, each language is good for its specific task, but can't (easily) do anything else."

Correct, let XSLT do what XSLT does (transform XML), and fill in the rest with Java. I've been paying attention to XProc for a long time and seems to be good fit for what _it_ does, (manage series of XML transformations).

"All I need to do is use that XSLT directory listing function... that function that doesn't exist."

Well, that's true. I'm surprised that somebody extolling the virtues of Haskell would miss this point, but XSLT is supposed to be a pure-functional language. You should't make side-effect/non-deterministic calls during a transformation. Furthermore, since he discovered the ability to write to multiple output documents in XSLT 2.0, I'm surprised that he didn't think of multiple _input_ documents.

The answer here would be to use java to produce all of the necessary input before the xslt/xproc pipeline. Create a temporary DOM filled with just a directory listing, you can configure Saxon to select on arbitrary documents that you create, and do it all in memory. Xproc is meant to make transformations composable in case you don't explicitly know everything beforehand, like if there's dynamically generated file content that gets populated from earlier transformations, but I think it's less useful than XSLT.

"Contrast this with the DOM model from Java."

Well, an API discussion on Java/DOM is a different matter entirely.

"Ant and XSLT are not designed for modularity."

Yes, they are. They are modular with respect to their domain models.

If the point was "Well, a client mandated the use of Java, but it wasn't so bad because I was able to do everything in XSLT and XPROC", it would have been interesting. Furthermore, one might have said, "If XSLT was a DSL written as an embedded API in a friendly language with extensible syntax like haskell, ruby or scala, it would have cut out the middle man".

To claim, however, that languages that aren't general purpose are dangerous becuase, well, they aren't general, is bit of a stretch.

</comment><comment><USER9> It's not responding. here's the google cached version: [http://webcache.googleusercontent.com/search?q=cache:5Jcrt8T...](http://webcache.googleusercontent.com/search?q=cache:5Jcrt8TgClAJ:www.yesodweb.com/blog/2011/08/perils- partially-powered-languages+&cd=1&hl=en&ct=clnk&gl=au&client=ubuntu)

<comment><USER10> That version still tries loading resources from the down domain. Adding the parameter 'strip=1' (or following the 'text only' link) does not.

[http://webcache.googleusercontent.com/search?q=cache:5Jcrt8T...](http://webcache.googleusercontent.com/search?q=cache:5Jcrt8TgClAJ:www.yesodweb.com/blog/2011/08/perils- partially-powered-languages&hl=en&client=ubuntu&hs=JrY&gl=au&strip=1)

</comment></comment><comment><USER11> I think the missing concept here is composability. Hamlet composes cleanly with Haskell, XSLT doesn't. Although it should be pointed out that Microsoft's XSLT implementation is more than capable of running arbitrary code.

</comment><comment> loup-vaillant > _The magic features that's missing here is sum types. There is no good > replacement in Java, and it precisely the right tool to model nodes in XML. > Added to that the requirement to use mutable data structures here and it's > painful. And don't even get me started on the difference between a null > string and an empty string in the API._

Yess! <http://loup-vaillant.fr/articles/classes-suck>

Maybe learning Java and its ecosystem isn't worthwhile after all.

</comment><comment><USER12> "Contrast this with the DOM model from Java"

More like from w3c (<http://www.w3.org/TR/DOM-Level-2-Core/>), but yes, shipped with Java. This is like complaining about DOM traversal in JS. There are other libraries/interfaces one can use for traversing XML other than what is shipped with the lanugage.

Seems strange to compare languages based on nsomething in a core lib of one and not in a core lib of another.</comment>


FDA approves GE AI system to detect collapsed lungs - <AUTHOR> https://www.cnbc.com/2019/09/12/ges-health-unit-wins-first-fda-clearance-for-ai-powered-x-ray-system.html <comment><USER2> is this just an american thing? why on earth does it take so long? i suffer recurrent spontaneous pneumothorax so im no stranger to them, whenever it happens i go to A&E get an xray and they usually tell me there and then if ive got a collapse</comment>


Should you be scared of Unix signals? - <AUTHOR> http://jvns.ca/blog/2016/06/13/should-you-be-scared-of-signals/ <comment><USER3> If you've ever read the Lions' Book commentary on 6th Edition Unix, you'll notice that many parts of the API as implemented back there are pretty solid -- quality, well designed interfaces that have stood the test of time.

Signals are not one of those parts. The 6th Ed signal handling code reads to me as somewhat of an afterthought whose use cases were mostly "kill the process for a fatal signal or terminal ^C", "ptrace for a debugger" and maybe SIGALRM. The data structures don't allow a process to have more than one pending signal -- if a new one comes along the fact an old one was pending is simply dropped. Running a signal handler automatically deregistered it, leaving a race condition if two signals arrived in close succession (this is a well known bug fixed by BSD later). And EINTR is an irrelevance if signals are generally fatal but its effects spread like poison through every other kernel API if you need your program to be reliable even with signals being delivered.

The worst bugs and races were fixed up by the BSD folks and others, but the underlying concept is an unfortunate combination of "basically irredeemable", "indispensable" (you have to have some kind of "kernel tells you something has happened" API, and signals are what we got) and "insidious" (thanks to EINTR). I think they're a strong candidate for "worst design decision in unix".

(PS: one of the reasons they stand out in 6th Ed is that so much of the rest of that code is so good!)

<comment><USER4> >The worst bugs and races were fixed up by the BSD folks and others, but the underlying concept is an unfortunate combination of "basically irredeemable", "indispensable" (you have to have some kind of "kernel tells you something has happened" API, and signals are what we got) and "insidious" (thanks to EINTR). I think they're a strong candidate for "worst design decision in unix".

Suppose you were to throw the whole thing out and write a _good_ replacement (and backwards-compatibility be damned), what would it be like?

<comment><USER5> _Suppose you were to throw the whole thing out and write a good replacement (and backwards-compatibility be damned), what would it be like?_

Steal the best bits from Windows NT, and improve the existing mechanisms.

Kill signals in their current form. Build a general-purpose notification mechanism consisting of a _mutex_ and a _message_. Possibly allow a process to have more than one message queue (Windows makes this really, really easy).

All IO, networking and informational signals (SIGWINCH, SIGCHLD etc) then come as messages (these may have to be fixed size, but anything from a few words to a 4k page would do). select, poll etc are replaced by waiting on a mutex. You can put all your worker threads waiting on that mutex. A message arrives. The kernel wakes _one_ waiting thread and gives it the message (via an atomic deque-or-block syscall). You don't have to do any O(n) processing to work out which socket it relates to as the kernel has helpfully put it in the message.

In the deluxe 4k page version, a 1500-byte ethernet frame arrives, is DMA'd into the top half of a page, the kernel inspects it and sets message headers to say where the data is, and hands it directly into the userspace of a waiting process.

The one downside of this is that UNIX pipe programs become slightly more complicated. Rather than just doing "while(read()) write()" you'd have to switch on the type of message recieved and implement your own abnormal exit functionality. This could probably be tidied away for you inside the standard library.

External process control mechanisms would have to be built for killing processes and suspend/resume.

<comment><USER6> Unix already has a general notification mechanism in the form of poll and select, no need to add a new one. The problem is not all interesting events are not portably delivered via a file descriptor, but that can be more easily extended (as done by lot of unices, including linux) than coming up with a completely new primitive.

But some messages really must be delivered synchronously and can't normally be queued: SIGSEGV, SIGFPE, SIGBUS, etc. There is really no way around interrupts.

BTW mutexes are not for signaling. What you want for signaling in a queue are semaphores, events or condition variables (or even file descriptors, like eventfd).

<comment><USER5> Well, the brief was to "throw the whole thing out", including select (which is bad) and poll (which is merely adequate).

The machine traps are interesting in that they should only be generated locally - there's no sensible case for injecting SIGSEGV into other processes. Arguably we should learn from Windows "structured exception handling" here. There are two sensible things to do with traps (other than sudden death): hand over to a callback of some kind (which should be told about the state of the stack), or turn into a language-native exception and throw that.

<comment><USER6> Poll is perfectly fine for the very large majority of unix applications which do not need to scale to tens of thousands of sockets.

The handling over to callback is exactly what is done by unix signals. Converting to exceptions can be implemented on top of signal handlers, but note that even MS stopped mapping by default structured exceptions to language exception a while ago, at least in C++, as unwinding the stack, destroying state and potentially calling destructors is the last thing you want on a segmentation fault or other unexpected events.

<comment><USER5> _The handling over to callback is exactly what is done by unix signals_

Not quite, there are quite a lot of restrictions on what you can do in a signal handler. It ought to be possible to design a callback mechanism without those restrictions. And a signal tells you nothing about its origin or what file descriptor / child process etc. it might relate to.

<comment><USER6> I assume that by restrictions you are talking about the async signal safety; this is inherent on the 'interrupt' nature of signals as they can happen at any point in a program execution, there is really no way around that. It would be of course nice if more functions where async signal safe (especially malloc).

Regarding the lack metadata, I agreed else thread that messages that carry such data ought to be transported via an explicit message queue, not via signals.

</comment></comment></comment></comment></comment></comment></comment></comment><comment><USER7> I found a paragraph in this article [http://www.linusakesson.net/programming/tty/](http://www.linusakesson.net/programming/tty/) very apt at describing what Unix signals are like:

      In *The Hitchhiker's Guide to the Galaxy*, Douglas Adams
      mentions an extremely dull planet, inhabited by a bunch of
      depressed humans and a certain breed of animals with sharp
      teeth which communicate with the humans by biting them very
      hard in the thighs. This is strikingly similar to UNIX, in
      which the kernel communicates with processes by sending
      paralyzing or deadly signals to them.

</comment><comment><USER8> Signals are like interrupts, and like interrupts, they're handled in an unusual environment. That's the main problem. You can be inside some nonreentrant library when a signal handler is called.

Most programs that do something complicated with signals generate an event in the signal handler and put it on a queue to be handled later. The queue should be lock-free, or there's a risk of deadlock.

<comment><USER9> Interrupts typically do not _observably_ interrupt currently running code. In a simple system (e.g. embedded system with no threads, all event-driven), the interrupt handler will run, then the processor will go back to running whatever it was running before. This is not so for UNIX signals, in case you are in the middle of a system call, because the mere occurrence of the signal will change the behavior of the interrupted code.

Yes I know it's not the same because in my example single-threaded system there's no such thing as a blocking call.

Actually I don't see a good reason why signals in unix would have to cause EINTR errors in system calls. Perhaps a better solution would be to let the system call go on normally. Since the signal doesn't observably interrupt code not in a system call, why would it observably interrupt code in a system call?

In case anyone thinks, "so you can detect the signal in the main code", that is a bad answer because whatever you do you will have race conditions if the signal happens just before you enter the system call. Your only chance is to use things like ppoll() which are designed for proper signal handling, and these things could work just as well in a hypothetical unix design with no EINTR.

<comment><USER6> You can siglongjump out of a signal handler [1]. If you sigsetjump right before doing a blocking call, you can reliably detect signals.

Another way to avoid the race condition in poll/select, before p{poll/select} were standardized, was to store the timeout parameter in a global variable and have the signal handler set it to zero. Finally there is the self pipe trick, which admittedly doesn't require EINTR at all.

[1] This is historical unix behaviour. At one time it was specified by the SUS, but it seems that it was dropped from more recent SUS/Posix standards.

<comment><USER10> > You can siglongjump out of a signal handler [1]. If you sigsetjump right > before doing a blocking call, you can reliably detect signals.

The problem with that approach is that if the system call has already returned by the time the signal handler runs and jumps, the system call's return gets clobbered. So if for example you're doing blocking reads/writes, you don't know how many bytes you read or wrote.

If your only blocking syscall is level-driven polling this approach is fine but the self-pipe trick is easier.

I wrote (10 years ago) a library to do something similar reliably. It required custom wrappers for every system call of interest so I could know by the instruction pointer in the ucontext_t whether the system call had actually run yet or not. [http://www.slamb.org/projects/sigsafe/](http://www.slamb.org/projects/sigsafe/) The library's a bit stale now; it doesn't do the vsyscall thing for example.

<comment><USER6> Duh! You are right, losing the results of partial read/writes is not acceptable. I guess on x86, completely unportably, you could check whether the current ip is pointing to a syscall/int instruction.

<comment><USER10> You probably want to jump if you're "just before" the syscall, too, though. So you end up with basically this:

syscall wrappers: [https://github.com/scottlamb/sigsafe/blob/master/src/x86_64-...](https://github.com/scottlamb/sigsafe/blob/master/src/x86_64-linux/sigsafe_syscalls.S) (probably could do something better with that thread local; and as I mentioned this isn't using vsyscall)

signal handler: [https://github.com/scottlamb/sigsafe/blob/master/src/x86_64-...](https://github.com/scottlamb/sigsafe/blob/master/src/x86_64-linux/sighandler_platform.c) (although it bugs me now that I iterate the whole array if the instruction pointer's not in any of the syscalls)

and just to be sure, a race checker: [https://github.com/scottlamb/sigsafe/blob/master/tests/race_...](https://github.com/scottlamb/sigsafe/blob/master/tests/race_checker/race_checker.c)

</comment></comment></comment></comment></comment></comment><comment><USER11> This is FoaF-level stuff, but:

I used to work with a guy who in a past life was an HP-UX dev. He told me that the guys who worked on the signals support in the OS had a 10-foot pole between their cubicles that had a flag on top reading: "You must be THIS tall to use signals."

<comment><USER12> What's FoaF? (RDF?)

<comment><USER13> Friend of a friend

</comment></comment></comment><comment><USER14> I've linked to this before, but AFAIK it's still relevant as the gotchas regarding signals haven't changed. Slides from a talk titled "Signal Handlers" from OpenBSD developer Henning Brauer : [http://www.openbsd.org/papers/opencon04/index.html](http://www.openbsd.org/papers/opencon04/index.html) To answer the articles question: should you be scared of Unix signals ? No. But you shouldn't do anything complicated in the signal handlers.

</comment><comment><USER15> BitKeeper uses signals to implement a paging data structure from a compressed backing store. I allocate the memory for my data structure that is backed by a file on the disk and then use mprotect() to mark that memory as read-only. Later when trying to access that memory a signal handler traps the access and loads and decompresses the data from disk into memory.

This is only done for unix systems that implement the sigaction() POSIX signals. It is tricky to get right, but it does work.

BTW I did find I could never get OSX 10.4 to work correctly, but by 10.7 Apple had finally fixed the bugs in their signal code.

<comment><USER16> Oodbs used a similar technique to translate addresses from a large "global" address space into smaller "local" one. Here is a paper if you're interested (ftp://ftp.cs.utexas.edu/pub/garbage/swizz.ps). Did you discover this technique on your own? At any rate, very cool.

</comment></comment><comment><USER17> >SIGSEGV is a very important signal. It happens when your program tries to access memory that it does not have. An appropriate reaction might be to

        allocate more memory
        read some data from disk into that memory
        do something with garbage collcetion (but what? I'm confused about this still.)

What? Are there any Real World Programs which do anything other than print a stacktrace and exit? I don't think this person gets what a segfault is.

<comment><USER18> If you had a Green threaded program and one of the threads segfaulted. You would probably want to catch Segv and kill that thread. (Not killing the OS thread running it).

I've also seen is used to implement a distributed malloc. When a segfault occurs, the handler messages the programs peers asking if they have the data for that address. If so the peers sends the page and the handler maps in a new page for that address with the correct data in it. This is essentially implementing a page fault handler in user space. (For some network backed memory).

<comment><USER6> Why would you only want to kill that green thread? On any thread implementation I'm aware of, an unhandled segfault kills the whole process. Anything else is disaster waiting to happen.

</comment></comment></comment><comment><USER19> As others have said, there's peril to be had there for sure, so tread carefully. Minimize the scope of your handler is the best advice, certainly also refer to "Async-signal-safe functions" in signal(7) if you must use libc funcs.

One challenge in a distributed system when there's (ab)use of signals is finding out which process issued a signal. There might be a better facility to do it now but I've used systemtap [1] to find out who the sender was with satisfactory results.

[1] [https://sourceware.org/systemtap/examples/process/sig_by_pid...](https://sourceware.org/systemtap/examples/process/sig_by_pid.stp)

</comment><comment><USER20> _Except for SIGKILL. When you get sent SIGKILL nobody communicates with you, you just die immediately. But the rest of the signals you 're allowed to install signal handlers for._

SIGSTOP also cannot be caught nor ignored.

<comment><USER21> or blocked.

</comment></comment><comment><USER9> The worst thing about signals is that they interrupt whatever system call the thread is currently inside (EINTR). This is not typically observed but can have dire consequences randomly. For example, last time I checked, in Python 2.7, a signal that invoked a signal handler will cause a running print() to throw an exception. Here you should consider signals like SIGCHLD which you want to handle and not kill the process.

A particular case this happens is when doing event-driven programming. The only way to be sure that you don't have such bugs lurking is to setup signal handling such that a signal cannot possibly interrupt unsuspecting code. Currently, I'm aware of two solutions, both involve blocking signals:

1\. Block relevant signals in the main loop (or generally all threads) and use signalfd to detect and consume signals (or similar mechanisms on other platforms, e.g. kqueue).

2\. Start a dummy thread whose only purpose is to handle signals, leave relevant signals unblocked in this thread and block them in all other threads. Write the signal handler to communicate the signal to your main loop via the self-pipe mechanism or similar.

Note that solution (2) can usually be implemented for an existing framework without changing that framework - you only need to add code to main which starts that thread then blocks signals, before any other threads are started.

I consider "fixing" code to be robust to signals a non-solution, because you would have to verify every single piece of code running in your program, including third-party libraries.

<comment><USER22> > For example, last time I checked, in Python 2.7, a signal that invoked a > signal handler will cause a running print() to throw an exception.

Python 3.5 fixes this – system calls are now automatically retried:

[https://docs.python.org/3.5/whatsnew/3.5.html#pep-475-retry-...](https://docs.python.org/3.5/whatsnew/3.5.html#pep-475-retry- system-calls-failing-with-eintr)

</comment></comment><comment><USER23> I've never seen a safe signal handler beyond a SIGTERM that sets a "volatile int time_to_quit = 1" for a main loop to pick up on later...

<comment><USER24> volatile int isn't necessarily safe. volatile sig_atomic_t would be, however.

</comment></comment><comment><USER25> YES. Especially when there are much better ways of handling OS interrupts to your program -- like Structured Exception Handling under Windows.

</comment><comment><USER6> The big problem with unix signals is that they have been abused to deliver some messages that should really be delivered via a message pipe (e.g. SIGCHD, all the terminal/tty specific signals). The other is that the set of signals is limited and signal handlers are a process (or thread) wide resource, so it is hard to make use of them in a library.

Other than that, the general ability of interrupting and delivering a message to a thread no matter what is doing is necessary and signals are a way to implement that. Exceptions are another way, but that can be implemented on top of signals.

edit: but there is really no excuse for EINTR. The "Worse is Better" essay has something to say about this.

</comment><comment><USER26> Consider this code highly experimental and yourself highly mental if you try and use it in a production environment

[http://www.kegel.com/c10k.html#examples.nb.sigio](http://www.kegel.com/c10k.html#examples.nb.sigio)

</comment><comment><USER27> On linux, the behavior for locking a mutex (I tested a GNU C++11 std::mutex) from a signal handler is to consider it (at least for the interrupted thread) to have been unlocked. This allows intuitive synchronization from handlers and avoids deadlocks, which I'm assuming is facilitated in the kernel-futex design. If any kernel hackers want to chime in on why this works (and is safe (is safe?)) in the face of most unix specifications, generic docs and articles like this it may be enlightening.

<comment><USER6> You are well into UB land. The behaviour you describe is very dangerous as the signal handler will be accessing the mutex protected data structure while it is in a potentially inconsistent state.

The right, portable way to signal from a signal handler are POSIX semaphores that on glibc are a thin wrapper over futexes. Any data structure access must be non blocking.

Edit: autocorrect

<comment><USER27> I should mention I was using x86. My initial assumption was that the kernel simply references the robust list (even if it was initially entirely resolved in userspace), and yields back to the interrupted thread -- I should emphasize my test showed the kernel _breaks into the lock_ and presents a semi-coherent _as-is_ structure entering and exiting the handler's lock. Of course this is all way way UB for portability or complex structures indeed...

<comment><USER23> Even on x86, you could have a pthread_mutex protecting a struct with two integers that need to be updated "atomically", and have a signal delivered in the middle?

<comment><USER27> Sure, and then the handler only sees one integer as updated and the other integer will be updated after the handler. The lock gets silently broken unfortunately, but there's probably a useful reason for why this is. It could just deadlock instead.

<comment><USER6> Deadlocking would be the ideal outcome. Deadlocks are easy to debug. Silent concurrent memory corruptions not so much.

</comment></comment></comment></comment></comment></comment><comment><USER28> Also, signals become much easier to deal with if your program is single- threaded. Once threads get involved, it becomes more complex to know which thread(s) will receive a given signal.

<comment><USER29> > Once threads get involved, it becomes more complex to know which thread(s) > will receive a given signal.

well, one approach that might be worth looking into would be to designate a special thread as a signal-handling-only thread. others just block every signal that can possibly be blocked. this signal-handling-thread then communicates the signals etc. to others as needed.

prima-facie, this boils down to signal handling for single threaded programs. what might be the downsides ?

<comment><USER10> People say "signals" as if they're just one thing, but I find it more useful to break them into two categories:

* process-directed signals such as SIGHUP, SIGINT, SIGWINCH, SIGTERM, SIGQUIT, SIGCHLD. They come from outside the process, including the `kill` command, the init system, and the terminal. For these, a dedicated signal-handling thread is a common, practical approach. Even if your program is single-threaded before implementing signal handling, creating a new thread might be the best approach. Or you could integrate signal handling with an event loop via the self-pipe trick.

* thread-directed signals such as SIGSEGV, SIGFPE, SIGBUS (the preceding are all machine exceptions), SIGPIPE, SIGPROF, or anything sent by pthread_kill / pthread_sigqueue. If you need to handle these signals (usually for diagnostics), by definition you have to do it in the thread in question. And you almost certainly need a traditional signal(2) / sigaction(2) style signal handler.

</comment></comment></comment><comment><USER30> When I first started programming UNIX I thought SIGIO made sense as a good mechanism for I/O multiplexing. I thought this because of much previous experience with interrupt handlers in the embedded world. However at the time, it just did not work (no sigsuspend) and even today it's a big mess. SIGIO should just be removed- it's the wrong way to handle I/O in UNIX.

</comment><comment><USER31> I think these days we all should use sigaction instead of signal()? why is this totally missed in the post.

[http://stackoverflow.com/questions/231912/what-is-the- differ...](http://stackoverflow.com/questions/231912/what-is-the-difference- between-sigaction-and-signal)

</comment><comment><USER32> I would say: Oh, yes, be as afraid as you can be. But don't let that stop you from figuring out why it is perfectly rational to be afraid of signals ;-)

Now, it is not impossible to use signals, but there are many opportunities to screw it up, often in non-obvious ways (so, things seem to work, but it's not actually reliable). And at the same time, signals almost never give you any advantage over alternatives if you do it correctly. That profiler thingy might be one of the rare cases where it actually makes sense.

In particular, what tends to be so tempting about signals is that they are executed "immediately", so you get to react without any further delay, no matter what else your program is currently doing--who wouldn't want that? Except that doesn't actually work, because you need to somehow access the state of your program in order to actually do anything useful with the signal notification. But you cannot access that state unless you can be sure it's in a consistent state and that your accesses won't interfere with what your program is doing in some unpredictable way. Just like in multithreaded programming. You have to somehow coordinate with your program to make sure things happen in an orderly fashion. Which essentially means that you only can access the program's state at certain times when the program isn't currently using it. Like, when it is unlocked. Except the signal handler potentially preempts your program, so you can't use locks to perform the coordination, because that could deadlock. Except if you were to use locking primitives that also block signals, so that preemption during critical sections can't occur. But then, you effectively have a weird polling solution (the unlocking at the end of the critical section/before entering the event loop dispatcher effectively acts as if you were polling for signal events).

Also, you cannot even reliably queue signals without potentially dropping some. Now, the kernel does that anyhow, so you can't rely on all signals being delivered individually anyhow, but it still is important to understand why that is (which is also why the kernel behaves the way it does): If you consume events, you have to either have some mechanism to slow down the source to prevent it from generating events at a higher rate than you can handle (like, if you can't keep up reading from a pipe, the writer end of that pipe will block in order to stop it from producing more data), or you would need potentially infinite amounts of memory to be able to store all those events for later processing. Now, the latter isn't really possible, of course - <USER2> it's even worse in signal handlers because you cannot really allocate memory there because there is only one memory allocator in the libc and that most definitely is not reentrant (like, you cannot allocate memory right in the middle of your thread freeing memory).

What this boils down to is that you always have to somehow defer processing of signals to some point in time where you can actually safely access your program's state, which is something that you can achieve with pipes and sockets much more easily.

</comment><comment><USER33> This is one of the great counter examples to betteridge's law.

</comment><comment><USER34> Signals are not scary if you read the docs! Perhaps you could tone it down with the exclamation points!</comment>


Ask HN: A year to do my own thing – how should I prepare? - <AUTHOR> My partner has got an amazing job offer (for a year-ish) in an area that doesn't have many software engineering opportunities. I'd like to take that time to do something I've always wanted - start my own company, preferably building a SaaS product.
I have a full-time job now as a software engineer in the bay area. There's a year and three months before we leave California.
What can I do now to prepare? What skills should I learn? What books should I read? Has anyone here done this before and do you have any advice? <comment><USER2> Solo startup founder here (of a not so successful SaaS startup yet(!)). First of all make sure you have a lot of money to spend. I know you will probably be able to code it up yourself (just like I do), but you will have spendings in stuff like advertisements, graphics, email outreach programs, hosting and stuff. Depending on your niche, you will probably need a LOT of advertisement money.

First of all. Try to find your thing. What makes you super excited (next to coding)? DO A LOT OF RESEARCH on that. Seriously, I can't stress that enough. One of my mistakes. Make sure you find something that you can improve, where is an actual market (still a need for it) and what doesn't take 10 years to build by yourself.

Make sure you create something that is different and better than other products on the market. That makes it soo much easier to market.

Things you should learn right now:

\- Get the basics of accountancy. I know that it is pretty boring stuff, but doing this right from the beginning will save a lot of work later on.

\- Read about advertising; funnels, copywriting, value adding, facebook marketing, influencer marketing and so on. Just consume it all and don't be afraid to test things.

\- Save up a lot of money. You will likely run out of money sooner than you think. Everything costs money.

\- Start interviewing people that are in your target market. Find out what you can do to make their lives easier. Try to sell time and/or money (as in savings) with your startup.

Last but not least, just do it :). Good luck!

</comment><comment><USER3> If you don't have any great ideas, I'm looking for partners...I have way too many ideas than I cold realize in a lifetime.

I'd suggest not to read too much...start building! Get stuff out there. Be careful in terms of what idea to work on...ideally something you're passionate about and that can generate revenues fast and that you can build on your own. You should be able to come up with say 100 ideas, maybe 10 of which are promising. I'd also strongly suggest looking for a business partner (congrats sounds like you have a great life partner :-D ). Also get mentors. I think having a mentor+partner is far better than reading even 100 books about building a business. Btw, the NSF SBIR deadlines are in 2 weeks, you could apply for R&D funding from them if you have an idea you're somewhat confident in.

No reason not to start building your SaaS service now btw...see if it gets somewhere before you take the time off.

Also, focus on living...sports, meditation, doing stuff inherently enjoyable for you...

</comment><comment><USER4> This might interest you: [https://groups.google.com/forum/#!forum/business- bootstrappe...](https://groups.google.com/forum/#!forum/business- bootstrappers)</comment>


Microsoft is incapable of innovating - <AUTHOR> http://gist.io/3318944

<comment><USER2> Microsoft is in a lot of trouble certainly. Reading both sides of the aisle on Microsoft, I think the products Microsoft produces for Businesses (SQl Server, Office Pro, etc.) will keep them from losing a significant chunk of PC sales to Businesses. However, Businesses only account for 40% of Microsoft PC Sales (based on Calculations I did off of Microsoft earnings press releases).

If they can't restructure their company they will have to eventually reduce in size significantly to maintain profitability.

</comment><comment><USER3> Really? And what was Kinect? If not an innovation and a game changing product?</comment>


Why my students dump their boyfriends: The 3 most eye-opening ideas in economics - <AUTHOR> http://www.learnliberty.org/blog/why-my-students-dump-their-boyfriends-and-girlfriends-the-3-most-eye-opening-ideas-in-economics/ <comment><USER2> Reading this I tought "Huh, simplified economic concepts, ending on overpushing the idea of voluntary transactions a bit...smells a bit american- libertarian".

Click around...project of IHS...

[https://en.wikipedia.org/wiki/Institute_for_Humane_Studies#O...](https://en.wikipedia.org/wiki/Institute_for_Humane_Studies#Organization_and_funding)

None of the concepts are wrong, but things are _more complicated_. For a short summary on the idea of Inequality of Bargaining and consequential hollowing of the "voluntary" transaction you can check out [https://en.wikipedia.org/wiki/Inequality_of_bargaining_power](https://en.wikipedia.org/wiki/Inequality_of_bargaining_power)

Interestingly, one area where this is taken into account, is study design (i.e. thinking about when a reward will skew the results/be unethical towards participants)

For some discussion see: [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3646546/](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3646546/) [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2600442/](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2600442/) [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2600442/#S2titl...](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2600442/#S2title)

<comment><USER3> I think you're right, things aren't that simple, but I have the feeling when I used these 3 points in the past, things went better.

But on the other hand, I always have the feeling, relationships go better if they aren't emotionally evaluated too much.

Sunk Costs

I've seen relationships go to shit but people are like "we are together for 10 years now, I can't leave them!" even in face of domestic violence or general abuse.

Yes the 10 years were nice and you paid them with your lifetime, but do you want to pay the shitty part too or just leave it by the 10 nice years?

Nothing is Free

I've seen relationships between people who simply don't fit together, but one part wanted to keep the other around, because of ... reasons? The other was way out of their league, attractive wise, and knew it. The other part was rich, and knew it.

Sometimes the other part was even the almost perfect fit, but didn't get their life in order.

Revealed Preferences

I've seen so many people who say A and do B. Especially in relationships. Talk is cheap and I did it too, in the past, but if you always say you want kids and never have them, time is over someday.

</comment></comment><comment><USER4> > A common example to help explain sunk costs is the movie theater experience, > where a person buys a ticket and, 20 minutes into the movie, she realizes > that it is a horrible movie and it will only get worse.

Offtopic I know, but twice in my life I've walked out of a terrible movie at the theater within the first 30 minutes and gotten a refund from the manager. Don't think you have to sit through terrible movies!

<comment><USER5> That is absolutely absurd to me. I understand walking out, but getting the refund had to have caused some eye rolls and jokes at your expense after you walked out. Where does it end? Can you walk out and get a refund because you didn't like the last 20 minutes? I think this sort of speaks to the absurdity of some aspects of this "get mine" mentality cultivated among economists

<comment><USER6> Fair point. Hell, you could even argue that you didn't like the ending... Refund!

<comment><USER7> One thing you might notice when traveling a lot, the US attitude towards refunds (ie. when reasonable, and I would argue even when "slightly" unreasonable in the interest of customer service) differs a LOT from most countries attitude towards refunds (which can be summarized as essentially only when convicted in a court of law - and even then)

</comment></comment></comment></comment><comment><USER5> While I'm sure he knows this, most reasonably social college students reflexively trade up in dating and I would hazard to guess they are near equilibrium. Economics basically reifies these implicit social concepts. That said, most dating market choices are not easily explained with the perfectly competitive market in a vacuum analogy that gets used in economics 101. For example, the sunk cost bias is actually metarational in the sense that it asks: "Am I really right about the grass being greener on the other side? How important is it to me to trade up?" which incorporates the concept of subjective beliefs and risk which is not addressed in the perfect information scenario and may not even be something that's tractable to explain in a rational actor model

</comment><comment><USER8> I'm not really convinced by his third point "Revealed Preference — Actions Speak Louder Than Words". I mean it's a useful concept to understand some interactions but it seems to me it also fails on some simple examples like payday loans and software bundling.

"My point is that if the exchange is voluntary and there is no fraud or misrepresentation, then it is a win-win transaction." Though maybe it can be argued that with abusive loans and getting Windows on most computers the exchange is not voluntary?

<comment><USER7> How is a payday loan not a win-win transaction ?

The person getting the loan obviously values money now more than total amount of money, for some reason (which may or may not make this preference entirely voluntary).

The person providing the loan values total money more than having constant availability of all their money (ie. they're investors). And I'm sure you would argue they also value more money more than ethics/decency.

Ie. the reason the economy works is that while price may be the same between buyers and sellers, value is subjective. Therefore it is a win-win in that both parties increase their perceived value through this transaction. This is also how a mortgage works, for instance.

<comment><USER9> > How is a payday loan not a win-win transaction

Usually because the borrower is not in a rational state of mind, and because we as humans focus more on today than tomorrow. Payday loans (like the loan sharks of old) take advantages of this in order to put borrowers in positions that a rational, future conscious person would never get into.

Economics say one thing, but it's the humans in the equation which muck up these otherwise ideal economic principals. Ultimately, economics should be there to serve people, not the other way around; payday loans are there to exploit people in need, not serve those who are in tough situations.

<comment><USER10> We can't assume that all of the borrowers aren't in a rational state of mind. And I'd hesitate to even say _most_ of them aren't.

Payday loans serve a pretty specific purpose: covering short-term cash flow when you can easily pay off the interest in the next term. This is a fairly common problem for people on the low-income scale with little emergency savings. If a car breaks down, it may cost $350 to fix it, and that money is necessary _now_ and not 10 days from now. It used to be that people would ask for advances from their employers, but this is a solution that sidesteps that.

<comment><USER7> Excellent response.

The only thing I'd like to add is that you cannot design a system that allows for individualism and yet somehow does not require individuals "to be in a rational state of mind".

Besides, that is like attempting to "protect" a drug addict from the consequences of their actions. It is the one thing in the world that is worse for them than letting them suffer.

<comment><USER9> Yes, let's let the drug pushers continue to legally advertise and sell their harmful drugs, and be sure to assign the blame onto their customers.

Great analogy.

</comment></comment></comment></comment></comment></comment><comment><USER11> I doubt the examples he mentioned can be reduced to simplistic economic theories.

For the movie for instance people could stick on hoping things will get better and things could.

For relationships most are loaded with emotions that make us irrational and decisions to make or break would also involve a multitude of other factors well beyond the scope of economic theories of sunk costs and self interest.

Listen but make your own decisions. You learn by listening to yourself, making your own mistakes and taking responsibility for them.

</comment><comment><USER12> The sunk cost fallacy fallacy: you have perfect knowledge of what other options you have, all specific knowledge and experience acquired in your current course of action is worthless and persistence never pays off.

Given how prevalent the so called sunk cost fallacy is in humans, you would think smart people would give a bit more thought to its darwinian origins.

</comment><comment><USER13> I adhere rather vigorously to points 1 and 2 because I value my time over most things. But, I find 3 a stretch. A movie is overpriced when you are unable to realize the full potential of the market. Last I checked, piracy is still a problem.</comment>


This thing will open in two days. - c-bayprogrammer http://whytheluckystiff.net/SPOOL/PRESENTLY <comment><AUTHOR> I wonder what _why has planned? Is there a return to the Ruby community in his sights? Has he written another book on Ruby or is it all a lot of build-up for nothing? Stay tuned.

<comment> c-bayprogrammer I know right? I got interested in _why after he vanished (but before the big article). Loved his video on Hackety Hack and Kaxxt. Excited that he might come back after all... we'll see!

</comment></comment><comment> c-bayprogrammer Full text reads:

This thing will open in two days. Which means it isn't open right now. Sorry, it just isn't.</comment>


Fairphone – The phone that cares for people and planet - <AUTHOR> https://fairphone.com <comment><USER2> I would be more excited about a phone like this if I didn't have to use Android on it... is there even a viable, open alternative? What happened to Ubuntu Touch?</comment>


How Technology Wrecks the Middle Class - <AUTHOR> http://opinionator.blogs.nytimes.com/2013/08/24/how-technology-wrecks-the-middle-class/?src=recg

<comment><USER2> Technology doesn't wreck the middle class, but it certainly enables America's corporate bureaucracy to cut as many costly human labor positions as it can.

We could counteract that if invested in our educational system, and I mean _really_ invested in it. Don't just throw money at the problem, but strengthen and expand public institutions of learning. No more student loans and no more financial aid. I'm not necessarily against private schools and universities, but all our current system does for lower-middle-class people is straddle vulnerable people with mountains of debt for a educational experience of questionable quality.

</comment><comment><USER3> Outsourcing has done much more harm to the american middle class than technology. For every job lost to automation in the US there are many that are lost to outsourcing.

<comment><USER4> Technology has made outsourcing much easier providing tools such as Skype.</comment></comment>


Decriminalizing Addiction - <AUTHOR> https://medium.com/@catharine_75466/its-rare-to-find-any-silver-lining-in-the-opioid-crisis-72c6ce4500a1 <comment><USER2> Is it just me or are words losing their meaning? By definition addiction isn't a medical problem. Honestly, Satan explained it best... [https://youtube.com/watch?v=cU8KV35Tz2I](https://youtube.com/watch?v=cU8KV35Tz2I)</comment>


Instagram has turned us against ourselves - <AUTHOR> https://streaking.app/posts/instagram-has-turned-us-against-ourselves-4be2eca50211 <comment><USER2> Set your profile to private and stop giving a shit about engagement. If you're selling something, great, make a themed profile and increase your follower count with as many #hashtags as you can cram into that comment section. If you're using it socially, post about your life and chill out on measures of popularity.

I do strongly agree with the idea that we need a better way to reach out to our friends. Posting a photo and getting likes isn't staying in touch. It's fine for acquaintances, but you should talk to the people you care about, not just check up on their recent posts.

<comment><USER3> I recently deleted facebook and instagram in an effort to take back my privacy. I really miss the stories feature on instagram. Stories don't have a concept of engagement besides views. People actually post what they're doing throughout the day in small, bite size pieces. I think it's a fantastic way to keep up with people.

<comment><USER4> Interesting - I see this less as "keeping up with people" and more voyeurism. It feels odd to me when I see someone who I haven't talked to in a while but I know all about what they've been doing/etc.

<comment><USER5> Eh idk. I'd say that it's more like going to a play to watch an old acquaintance perform while sitting in the way back where they can't see. Is that voyeurism? Because on social media, typically the idea is people opt to display their lives so that they can be observed. Idk for me voyeurism implies more of a one sided observation where the observed isn't really aware or intending.

</comment></comment></comment></comment><comment><USER6> I don't care about how many likes or how many followers I get. I use Instagram to share my photography which is my hobby. I only follow my friends and people whose posts I genuinely want to see. Through Instagram I've been able to connect with other likeminded photographers that inspire me with their work and support me in mine. I also find it a great way to keep up with old friends that never used Facebook in the same way.

If your happiness is dependent on the attention you receive on these social media apps, there are likely deeper problems that you should address beyond simply deleting the app and telling everyone else who uses it to do the same.

There's a certain irony to all of these posts that have been cropping up lately on how "I deleted (insert social media service here) and it made me happier". Many of these posts cite the cessation of the race for validation as the reason for their increase in happiness. If you weren't expecting the same validation that you got from the service you just left, would you have really made the post? Couldn't you have simply just quit and be done with it? Deleting Instagram may temporarily improve your mental health, but it isn't a cure for a deeper underlying problem.

<comment><USER7> > I use Instagram to share my photography which is my hobby.

But Instagram has horrific resizing and compression algorithms that make good DSLR photos look like artifacted junk. They're designed to plaster over the smudgy quality of phone photos and when you feed them a 20MB 100% JPEG it all falls apart.

I realised this when IG photos from my ancient 350D beater were less artifacted than photos from the 1Ds3...

And they do something to colours, red-shifting blues to purples; presumably for more _POP_ on mobiles.

You'd be better using a proper gallery site.

<comment><USER8> that no one would visit

</comment></comment></comment><comment><USER9> I feel this way about social media in general.

I completely deleted all of my social media profiles about three years ago. A few weeks back, I created an entirely new twitter account because I've been giving more software talks lately and I've noticed that I'm the only speaker without a twitter handle.

But I find myself falling into the engagement trap constantly, since I still have a tiny following. In trying to think "what should I tweet that will get likes?", I'm already conditioning myself to pursue engagement.

The thought of getting my twitter following back to what it was only a few years ago seems really daunting, and I'm already put off by the thought a few weeks in.

<comment><USER10> "I'm already conditioning myself to pursue engagement."

We are all brand managers now.

<comment><AUTHOR> You could say we are all influencers now

</comment></comment></comment><comment><USER11> > People are reduced to a single identity

You can have multiple accounts and the Instagram UI makes it easy to switch. You can click the name of the account and a drop down appears. You then click the account you want to use and it immediately switches you without any hassles.

Most people I know (18-28 demographic) have several accounts.

I own a reptile and my main account is reptile posting along with some nature photos taken from the odd times I go on hikes. This account is my "nature photography" account. It's the one I use to enjoy the gamification part of Instagram. I enjoy hunting for likes and adjust the photos I post there based on reception.

The second account is a sh*tposting account that is private and is filled with inside jokes. This account is only followed by close friends.

My third account is my family account. It's filled with family photos and my mom and aunts follow it. This account is also private.

My fourth account is my developer / workplace account and has no photos. It is temporary because it is registered using the corporate email account and when I change jobs, I create it again from scratch.

<comment><USER12> Most kids I know have one or more _finsta_ accounts plus a "real" one that they let their family follow.

<comment><USER11> Exactly. It's so common that there's even lingo around it. Finsta and Rinsta. Fake instagram account / real instagram account.

<comment><USER13> Frame or Fake?

<comment><USER11> Autocorrect. Thanks, caught it in time to edit.

</comment></comment></comment></comment></comment><comment><USER14> My dopamine response system has apparently never bought into the idea that likes actually determine my value in any way. I seem just use them to see what specific friends or colleagues are interested in and invite them for a specific activity. Vegetarian? Invite them for pizza not a BBQ. Outdoorsy? See if they want to go skiing or hiking some time. Based on what I see and hear I feel pretty lucky.

<comment><USER15> If you are actually using likes as useful data points for meaningful action you are way ahead of most people. To me, and I imagine many others, likes are just a passive acknowledgement of popularity with only wafer thin meaning. Not doing anything with those likes is part of what makes them such a problem and one of many reasons I avoid social media.

</comment></comment><comment><USER16> Counterpoint: IG allows you to curate an online photo album about yourself and either broadcast it to the world or distribute it to a permissioned list, and this has significant value for many people.

It also has intrinsic negative value for many, in the way outlined by the author (and also described by the seminal Wait but Why post [0]). People see their friends posting snapshots of their nominally awesome lives and feel pressure to keep up, and basically everyone makes each other more miserable by generating FOMO in others, etc.

I'm not saying that this _sehnsucht_ -generation isn't real, or that it doesn't mess some people up -- it is and it does. But if we're judging IG on its overall merits the downside has to be weighed against the fact that IG helps people learn about each other through a pretty elegant interface -- right?

Also, the author seems to be eliding the differences between a) best practices for building and monetizing an IG following as an influencer with a public- facing account and b) the general stress of 'keeping up with' your college classmates:

> We can talk about free or paid apps, ads or donations, we can talk about > tipping and buy me a coffee, or patreon subscriptions. We can talk about all > of that, or we can get to the heart of what really matters. Things that are > easy to do, aren't always the best things for us.

By my reading, in this passage he is conflating the measures IG influencers take to help themselves make money on Instagram with the stress and angst that IG users who are not trying to make a living off of IG posts feel with respect to keeping up with their high school classmates and whatnot. Seems like a pretty clear category-mistake to me.

[0]: [https://waitbutwhy.com/2013/09/why-generation-y-yuppies- are-...](https://waitbutwhy.com/2013/09/why-generation-y-yuppies-are- unhappy.html)

<comment><AUTHOR> I've never heard of waitbutwhy, wow this site is amazing.

You're right. I was conflating influencers together with regular users.

I guess I don't usually separate them when I rant about IG, I rant about it quite a bit. It would be nice if it was all IG ads and regular users or if influencers were marked as such… maybe.

</comment></comment><comment> reading-at-work I see the reasoning, but I don't think it's necessarily true. Look at someone like Joe Rogan, who has millions of followers but a fairly eclectic mix of content and no one thing that defines what he does (interviewer, commentator, hiker, traveler, hunter, MMA enthusiast, fitness and "nutrition" advocate, etc).

Come to think of it, most of the famous people I follow post random content as well, like musician Ola Englund posting funny videos of his kids or UFC fighter Derrick Lewis posting almost nothing UFC or fighting related. If anything, the unexpected content makes a person MORE worth following because it's not just generic self-promotion the whole time.

It's a mixed bag, and the author definitely has some warrant for concern, but I think it's overblown.

<comment><AUTHOR> I've noticed this too, like pewdiepie on youtube, similar situation. Of course he also spent years as the "guy who streams himself playing games"

</comment></comment><comment><USER17> There's something really unsettling about the way this article casually drops a Ted Kaczynski reference without, you know, even doing so much as alluding to the messed-up things that he did. There are probably better examples of people to use, right?

<comment><AUTHOR> Yeah you're right, definitely not a great person, but I used the reference because he turned out to be right about the negative effects of "over- socialization"

</comment></comment><comment><USER18> If you are "working on your personal brand" or whatever... sure. I just post pictures of stuff I do, and my friends see it. The end. I don't care at all about "getting engagements"

</comment><comment><USER19> Did anyone notice the website for this post? The author of this post seems to have created the site too:

\-- [https://streaking.app/about](https://streaking.app/about)

\-- [https://streaking.app/@sean](https://streaking.app/@sean)

This idea of tracking streaks is good; is there a meta-service/platform for monitoring "streaks" of "anything"?

<comment><USER20> Two big services in the indie-maker space are:

\-- Makerlog (free): [https://getmakerlog.com/](https://getmakerlog.com/)

\-- WIP (paid): [https://wip.chat/](https://wip.chat/)

Both allow you to record what progress you've made while also tracking the number of days in a row you've been delivering.

</comment></comment><comment><USER21> > deleting accounts and ostracizing yourself socially

I read this as the former implying the latter, and was reminded of a tweet by Mike Monteiro that was something like[1]:

> I've seen excuses from people who say they want to leave Facebook but can't > that would make heroin addicts blush

[1]: He was part of DeactiDay, so the account and tweet are no longer available.

</comment><comment><USER22> When I click this link I am "turned against myself" by what seems like an automatic history.back(). Is this a metaphor? (edit: A half hour later and it is still doing this for me despite other people seemingly commenting on the content of an article. I am using iOS 10.)

<comment><AUTHOR> Oh interesting… there shouldn't be anything like that there. In fact, it should work with js disabled entirely, assuming js is the culprit here. For what it's worth, I don't have access to iOS 10, but I did try it on Safari in the latest iOS and had no issue, sorry I can't help more

</comment></comment><comment><USER23> If the author is reading HN, please add something like this:

      p { line-height: 25px; }

The text is hard to read from being so bunched together.

<comment><AUTHOR> I am reading this, and yes I will do that! Thanks for letting me know</comment></comment>


Direct access to all the web's emails - <AUTHOR> https://emailhunter.co

<comment><USER2> *email addresses. Still very impressive and unsettling.</comment>


Handheld Devices Should Be Banned for Children - <AUTHOR> http://www.huffingtonpost.com/cris-rowan/10-reasons-why-handheld-devices-should-be-banned_b_4899218.html

<comment><USER2> 30 minutes a day of video games. LOL. In lots of games, a single level or mission takes double that time. This is just ridiculous.</comment>


Will cable TV be invaded by commercials? (1981) - <AUTHOR> https://www.nytimes.com/1981/07/26/arts/will-cable-tv-be-invaded-by-commercials.html <comment><USER2> Q: Will X be invaded by ads?

A: Almost definitely.

Even some major automakers seem to assume that the car of the future will include ads.[0] Amazing that car companies could've survived all these decades without them!

[0] [https://www.theverge.com/2017/7/10/15947784/audi-25th- hour-a...](https://www.theverge.com/2017/7/10/15947784/audi-25th-hour- autonomous-car-driving-work-time)

<comment><USER3> I thought I'd seen it all until _gas pumps_ started having loud auto-playing videos. I consider it one of the benefits of an electric car that I no longer see gas pump ads.

And this stuff always seems to hit "lowest common denominator" quickly. Once consumer-hostile methods prove some kind of worth, everyone seems to follow suit to compete (or just be as greedy).

<comment><USER4> For those still subjected to these who don't know: Most video-enabled pumps in the US can be muted by pressing the second button from the top on the column of four buttons to the right of the display.

I consider it a small quality of life improvement to not hear the same Seth Meyers joke two or three times while fueling.

<comment><USER5> I try this every single time and it's never worked.

<comment><USER6> I've never visited a gas station with ads more than once.

<comment><USER7> In my area you'd run out of gas stations quickly with this strategy :-)

</comment></comment></comment></comment></comment></comment><comment><USER8> My gym has guideless basic cable on the cardio machines. Anytime I channel surf I would estimate more than 50% of the 70ish channels are running commercials. Same when i stay at a hotel with cable. I'm surprised anyone is still willing pay for this.

Thankfully the new machines at my gym have Netflix.

<comment><USER9> You really have a TV on each machine at your gym? This is peak America

<comment><USER10> > You really have a TV on each machine at your gym? This is peak America

Some of the gyms in Melbourne Australia have TVs on all the treadmill machines. I am talking about normal gyms not some high end fancy gyms.

</comment></comment></comment><comment><USER6> > To date, the actual revenues from cable advertising, which totaled about $45 > million last year, are minuscule compared with the $11 billion for over-the- > air television networks and stations. But scores of big companies, including > General Foods, American Express, Procter & Gamble and Pepsico, are already > cable advertisers, along with innumerable used-car dealers and other local > businesses that can afford cable's relatively low rates. By 1990, according > to Paul Kagan, publisher of several cable industry newsletters, cable > advertising could exceed $2 billion.

Stunning.

We didn't have cable until the late 90s, and I don't have pay TV anymore, largely for this reason. "Premium" things are always dumbed down. First comes the ads, then the censorship. I'm not willing to pay for ad-laden, censored content, full stop. I happily pay for Spotify, but I won't pay for cable TV or XM.

<comment><USER11> XM was an interesting note there at the end. I realize they are still subject to FCC regulation but they seem mostly add free and uncensored.

</comment></comment><comment><USER12> The entire debt-based economy is based on extracting more money from consumers. Worth mentioning is this is not long after stagflation occurred in the late 1970s. As a side note, I have a strong feeling that in large corporations like Google expenses always tends to increase with revenue. One example would be housing and salaries, but there are probably others.

<comment><USER13> What does "debt-based" have to do with extracting money?

<comment><USER14> When money is easy, the incentives switch to increasing consumption, rather than investment in increasing productivity. Why spend time and money inventing a better mousetrap when you could just buy ten more of them?

The principle applies at every level of the economy (individual, corporate, government etc)

<comment><USER15> I don't quite see how that follows necessarily - high investment allows for maximizing per unit costs compared to "paycheck to paycheck". Not that consumer debt bubbles aren't a thing.

<comment><USER12> In this case, we have been running a trade deficit since the 1970s.

<comment><USER15> It is a world reserve currency as well making a deficit pretty much inevitable as long as it holds. Getting goods in exchange for spreading your currency's reach sounds like a pretty good deal to me. Effectively it gives a "virtual economy size" from worldwide dollar users over just producing for the local economy - not doing so in response would be deflationary. They need some sort of goods or services in exchange so the economic backing is provided for any outflowing currency.

<comment><USER12> The point is that it destroys local manufacturing though, leading to more and more goods being imported.

</comment></comment></comment></comment></comment></comment></comment><comment><USER16> >Although cable television was never conceived of as television without commercial interruption, there has been a widespread impression...

Cable companies, even though they now act as ISPs, where never conceived to track you browsing history and do with it what they will. And somehow there's a wide spread assumption that they won't.

</comment><comment><USER17> This is strange. I've consistently heard that it was a total myth cable was ever ad-free.

<comment><USER18> I remember the early-1980s cable landscape, when the only "cable" channels were what we could call premium channels now: HBO, Showtime, Cinemax, The Movie Channel, etc.; all the other channels were local over-the-air stations.

<comment><USER19> We got cable in 1981 and it was exactly this. None of the "cable" (premium) channels had ads. Some of them, like Nickelodeon, did add ads in the late 80's.

</comment></comment></comment><comment><USER20> The existence of cable ads is useful to me when my ISP tries to upsell me on television service.

"Cable? I haven't had that for about fifteen years. Does it still have ads?"

"Yes, sir."

"No thanks, then!"

</comment><comment><USER21> Will bears sell toilet paper in the woods?

<comment><USER22> This is one of the wittiest replies I've seen here.

Downvotes must have been because they didn't get it.

</comment></comment><comment><USER23> Wait until BCIs like Neuralink come out. Then there will be no way to escape ads.

</comment><comment><USER24> Apparently, Betteridge's law of headlines doesn't always hold up.

On a more serious note, it will be interesting to see if currently, ad-free on-demand services will undergo the same transition.

<comment><USER25> Amazon Prime includes "ads" for their own shows. I call them ads because they are on before the show I'm watching and I don't want to watch them. Luckily, for now, I can still skip them.

<comment><USER26> I thought I noticed that on an Amazon fire. It doesn't happen on my lg tv though.</comment></comment></comment>


Guaranteed basic income emerges as top policy priority for Liberal MPs - <AUTHOR> https://globalnews.ca/news/7330929/liberal-caucus-guaranteed-income/ <comment><USER2> What will happen to prices of scarce resources (e.g. single family homes) when everyone's spending power goes up by the same amount?

<comment><USER3> Nothing as foreign buyers is the engine driving that bubble. It would take outlawing foreign buyers to burst that bubble.

<comment><USER2> Maybe for Vancouver and San Francisco but not for the majority of other cities. Let's examine rent purely, then, since I imagine UBI isn't making a big difference for home purchases.</comment></comment></comment>


Full Text Search with Whistlepig - <AUTHOR> http://bugsplat.info/2013-01-09-full-text-search-with-whistlepig.html

<comment><AUTHOR> To the joker who searched for "(dasdsa#@!#@!K#...KJ#!@LKJ#@!LKJ+,.3,21/321" thanks for the debugging help :)

<comment><USER2> Post the refined version of your code?

<comment><AUTHOR> Oh, I just wrapped the query parser in a begin/rescue block. You can see it here: [https://github.com/peterkeen/bugsplat.rb/blob/master/page.rb...](https://github.com/peterkeen/bugsplat.rb/blob/master/page.rb#L56)

</comment></comment></comment><comment><USER3> Another alternative is to do the search on the client. This is the approach taken by the Sphinx documentation tool which generates static pages. It is popular with (but not limited to) Python. See <http://sphinx-doc.org/> In the bottom right of that page you can see a search box. "Exception" is an example search to try.

The way it works is that doc build time it generates a index file that contains various terms, performs stemming, stop word elimination etc. When you do a search the client javascript downloads the index, performs stemming on the search terms and does the lookup in the index. This is what the index looks like for that site in JSONP format <http://sphinx- doc.org/searchindex.js>

<comment><USER4> This is excellent; I developed such a solution some time ago, after asking on StackOverflow if such a thing already existed and being told no.

It's actually quite simple to do from scratch anyway. My solution involved being able to search non-consecutive terms on a page and return paragraphs containing those terms. AFAIK, in-browser search cannot do this, which is a shame.

<comment><USER3> Sphinx actually does show the paragraphs in browser. Try a search to see.

The source files for Sphinx are plain text in rst format (like markdown but with more functionality). It generates HTML from that, but (by default) the original plain text files are also included in the output. The search index tells it which pages match and the javascript grabs the plain text and shows paragraph matches.

</comment></comment></comment><comment><USER5> Very nice, but I see scoring as the important feature of a full text search, which this one doesn't offer. It's still makes sense to use it if you big enough number of documents or if query language suits you use-case, and you implement scoring on top of it, but it would be nice to have in the engine itself.

<http://fallabs.com/tokyodystopia/> is similar to this btw.</comment>


Why MarkoJS is fast - <AUTHOR> https://medium.com/@psteeleidem/why-is-marko-fast-a20796cb8ae3 <comment><AUTHOR> BTW, the benchmarks in January shows MarkoJS 40x+ faster than React on server side rendering ( [https://hackernoon.com/server-side-rendering-shootout- with-m...](https://hackernoon.com/server-side-rendering-shootout-with-marko- preact-rax-react-and-vue-25e1ae17800f) )

I do not get too excited for 20% improvement but 4000% improvement makes me interested. It can mean that you need 1/40 of your frontend servers.

If you currently have 100 servers to serve your dynamic pages with React, you may just 3 with Marko !!!</comment>


Primg – Generate prime numbers whose binary representation looks like any image - <AUTHOR> https://geonnave.github.io/primg/ <comment><USER2> Here is my Python implementation: [https://github.com/shabda/experiments/tree/master/prime_dino...](https://github.com/shabda/experiments/tree/master/prime_dinos)

I put up a show HN, but no one liked it :) [https://news.ycombinator.com/item?id=16198861](https://news.ycombinator.com/item?id=16198861)

<comment><USER3> You should have added "in python" to the title.

<comment><USER2> Possibly. But I think the immediate results from browser make this one easier for people to see what is happening.

<comment><AUTHOR> Hi shabda. I've seen your version when I was searching if someone has done this before. And you are right, I did it in Javascript because I wanted to share it with the world more easily.

<comment><USER2> Haha, awesome! Glad if it helped in anyway.

Are you putting your code on github or such? (edit: disregard the question. Its obviously at: [https://github.com/geonnave/primg/](https://github.com/geonnave/primg/))

<comment><AUTHOR> Yes it did, especially as a confirmation that such a thing could be done xD

So long and thanks for all the fish!

</comment></comment></comment></comment></comment></comment><comment><USER4> The example on [https://github.com/geonnave/primg](https://github.com/geonnave/primg) shows a binary number ending with zero; doesn't that mean it's even, and therefore divisible by 2?

<comment><USER5> If you decrease the binary number by 1, it becomes prime. Perhaps it's this bug:

[https://github.com/geonnave/primg/commit/7ec6cfaa4b581902ea1...](https://github.com/geonnave/primg/commit/7ec6cfaa4b581902ea160e684127e34f6747bc51)

<comment><AUTHOR> It is indeed! Haven't noticed the binary was wrong too.

</comment></comment></comment><comment><USER6> Not convinced I actually look like

      179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357110553379400815780032957688591226535854678434413850350192892043530395436831148532011789232552521569332295554081981793617293526812832242447096911185919439189235252915185597964786711096720343

tbh ;-)

<comment><USER7> I'm not 100% sure, but do you wear glasses?

I think I see how to view this. I can see a silhouette.

        17976931348623159077293
        05190789024733617976978
        94230657273430081157732
        67580550096313270847732
        24075360211201138798713
        93357110553379400815780
        03295768859122653585467
        84344138503501928920435
        30395436831148532011789
        23255252156933229555408
        19817936172935268128322
        42447096911185919439189
        23525291518559796478671
        1096720343

look at this and unfocus your eyes

<comment><USER8> It's the binary representation that looks like the image, not the decimal one.

</comment></comment></comment><comment><USER9> You could probably speed things up a lot using isProbablePrime(), at least to pre-filter candidate numbers. (Assuming you're using this library: [https://www.npmjs.com/package/big- integer#isprobableprimeite...](https://www.npmjs.com/package/big- integer#isprobableprimeiterations))

<comment><AUTHOR> I used isProbablePrime() before, when I had a 50x50 canvas. But it was still really really really slow. After changing to a 32x32 canvas, the difference between isPrime() and isProbablePrime() seemed negligible.

<comment><USER10> That makes me think that their probable prime implementation isn't that great or else that they're losing a ton of efficiency to the Javascript interpreter.

      $ time python -c 'import gmpy; gmpy.next_prime(2**2500)'

      real	0m0.443s

Was it taking a lot longer than that for you?

Edit: I can see that there is an element of luck in terms of how many candidates you have to look at, but I'm still seeing everything in this size range take under 2 seconds. Maybe it's a question of what probability of error you're accepting from the test?

<comment><USER11> GMP is very well optimized and implemented in assembly. There's no way that a JavaScript implementation can get anywhere close to that performance since JavaScript doesn't even have support for 64 bit integers. WebAssembly might be faster, but is still lacking many instructions commonly used for big integer arithmetic.

</comment></comment></comment></comment><comment><USER12> You could color the 1s and 0s - so the image is more obvious and enhanced.

</comment><comment><USER13> Relevant Numberphile on generating prime pictures: [https://www.youtube.com/watch?v=fQQ8IiTWHhg](https://www.youtube.com/watch?v=fQQ8IiTWHhg)

</comment><comment><USER14> Perhaps it shouldn't even bother generating a binary number that ends in '0'

</comment><comment><USER15> Is there a way to link to a number? Or enter a number to view the image?

<comment><AUTHOR> That is very a good idea! For now it is stateless & frontend-only. But I was thinking on improving it, like a prettier UI and adding a "print" button, or maybe a "export to png". If I ever add a server side to it, it will feature a share & see option.

Afterthought: actually, I was thinking on using IPFS to store stuff, but I do not know if its model applies to this scenario. Feedback is appreciated.

<comment><USER16> You could link to a number by just adding a query or hash with the base64 encoding of the number in 171 characters. You'd lose the original image of course.

Edit: I bet a RLE would compress down really nicely except for the bottom row if you want to reduce URL sizes

<comment><AUTHOR> Thanks guys, you can now access a prime dog right there: [https://geonnave.github.io/primg/#17976931348623159077293051...](https://geonnave.github.io/primg/#179769313486231590772930519078902473361797697894230657273429661642538456588077306078196596037783249291026990862829670919205888565609581869739105202524725614169647793002230079727461396703734603105685474079081886809070115786113168328330817484522518138348888081075292599304124949646601273927687076353436639295493)

</comment></comment></comment></comment><comment><USER17> These are very neat, but all of these I've seen the last few weeks use the same trick of putting some garbage at the end to make it a prime. I wish people would vary their techniques a bit: like, make it base 10 and make an ascii-art image, and introduce imperceptible noise to make it a prime. Or, vary the number of rows and columns, and maybe scale of the image, to make it prime.

We need to disrupt the "images as primes" industry!

<comment><USER18> Last time this kind of thing was on the front page I suggested a frame of noise around the image, which would work to hide the bottom corner.

</comment></comment><comment><USER19> Can you use this for encryption? Make the decryption key the prime number generated by this, and you unlock it by pointing the camera at the right thing?

<comment><USER20> No, not really: if you take a picture of something, it won't have the exact same pixel values every time you take it. A QR code would be way easier.

<comment><USER19> It's scaled to 32x32 black and white. The pixel values don't have to be that similar, only reasonable close.

<comment><USER21> But that's only 1024 bits, assuming values of each pixel is independant from its neighbors. Which it isn't, so you are well under 1024 bits.

</comment></comment></comment></comment><comment><USER22> > numberBigInt = numberBigInt.minus(1)

[https://github.com/geonnave/primg/blob/master/index.html#L82](https://github.com/geonnave/primg/blob/master/index.html#L82)

Could go double as fast subtracting 2 instead of 1 (why try the even numbers).

<comment><AUTHOR> I assume the BigInteger library, which offers isPrime() and isProbablyPrime() functions, already does that kind of optimization.

</comment></comment><comment><USER23> Is this in response to [https://mathwithbaddrawings.files.wordpress.com/2017/10/2017...](https://mathwithbaddrawings.files.wordpress.com/2017/10/2017-10-6-odd- number-theorists.jpg) ?

<comment><USER5> [https://github.com/geonnave/primg](https://github.com/geonnave/primg) links to [https://www.reddit.com/r/math/comments/7qpfls/does_there_exi...](https://www.reddit.com/r/math/comments/7qpfls/does_there_exist_a_prime_number_whose/) .

<comment><USER24> Previous discussion: [https://news.ycombinator.com/item?id=16192608](https://news.ycombinator.com/item?id=16192608)

The Python version I wrote and linked to back then (which is a bit less general): [https://gitlab.com/snippets/1694391](https://gitlab.com/snippets/1694391)

</comment></comment></comment><comment><USER25> This takes a very, very, very long time.

20 minutes in, it is up to 13388 in Firefox.

Funny enough, I ran the same image through Chrome, it said it was finish at iteration 458. I'm guessing it is not completely deterministic?

<comment><AUTHOR> So. In some cases, which I couldn't isolate, it finds the prime but won't stop the program. On average, it should only need from 400 to 600 iterations.

<comment><AUTHOR> I've found the problem that made this happen and it is now corrected.

</comment></comment></comment><comment><USER5> Source: [https://github.com/geonnave/primg](https://github.com/geonnave/primg)

</comment><comment><USER26> Ah, but can you generate a prime number that encompasses the full list of true statements, please? :)

</comment><comment><USER27> Would it not be preferrable to change as little bits as possible? Instead of counting up from your number you should first try to change single bits (one bit, two, three ...)

Changing a single out of 32 _32 bits gives you 1024 variations. Changing two already gives you 1024_ 1023/2 = 523776 variations.</comment>


Show HN: Secret for Workplaces - <AUTHOR>

Share Honest & Anonymous Feedback w/ Co-Workers
Please help me spread the survey to all your Corporate friends: https://chany2.wufoo.com/forms/company-culture-questionaire/
VoiceUp provide an outlet for employees to be a honest and transparent while remaining anonymity - improving employee engagement and addressing critical needs within the enterprise.
Learn more @ http://chany2.github.io/VoiceUp <comment><AUTHOR> Survey Links - [https://chany2.wufoo.com/forms/company-culture- questionaire/](https://chany2.wufoo.com/forms/company-culture-questionaire/)

Landing Page - [http://chany2.github.io/VoiceUp](http://chany2.github.io/VoiceUp)</comment>


How your phone is more powerful than ORION - <AUTHOR> http://www.dailymail.co.uk/sciencetech/article-2867009/How-phone-powerful-ORION-Computer-Nasa-s-Mars-spacecraft-processor-2003-Apple-iBook-G3.html <comment><USER2> Interesting that the dailymail looks and reads like the onion only it pretends to be for real:

 _The chips do not error check each other but instead perform exactly the same tasks, so that they can check the other for errors._

<comment><USER3> Also, according to the article there is only double redundancy. I thought critical systems like this always employed triple redundancy. It doesn't help too much if you detect a fault during launch and have to reboot both systems...

</comment></comment><comment><USER4> TL;DR: Orion uses rad-hardened chips, which are usually very slow compared with commodity hardware. But it also runs super-optimized and highly specialized code.

<comment><USER5> Also, people, I feel, get this impression that because Windows 8 takes forever to load and then Word takes an eternity, that they _need_ that speed. No, you need less bloated programs, and (I would seriously hope) that missile/rocket/spacecraft guidance and life support computers are not running bloated software!

</comment></comment><comment><USER6> Hopefully ORION has a better battery life than my phone

</comment><comment><USER7> Firstly I am surprised the Daily Mail created this piece, their readers care more about spending money on the NHS rather than space.

Secondly I was a little puzzled but the statement that Orion could be used to send people to Mars. If that were true then does that mean we are leaving them there to die?

</comment><comment><USER8> Daily Mail is a rag. I wouldn't believe anything they publish. I'm surprised it isn't blocked.

</comment><comment><USER9> How there will be more computing power dedicated to ORION while on mission than the daily mail can imagine.</comment>


Greasekit script implementing AutoPair Characters for form text fields - <AUTHOR> http://nirmalpatel.com/blog/2008/12/15a.html

<comment><AUTHOR> UPDATE: Fixed a bug where textareas and text inputs that weren't inside form tags were not modified. I also removed apostrophes as a paired character because it became annoying when I typed contractions.</comment>