HNHacker News
TopNewBestAskShowJobs

epidemian

1,261 karma · joined May 6, 2011

https://demian.ferrei.ro
submissionscomments
epidemian··on Where is Ruby Headed in 2021?
> Without those imports, how will people reading the code find the definitions? How will they track down the source code for all the methods being called?

I think in dynamic languages like Ruby and Python, there are two very different cases that we need to distinguish when thinking about this.

The first one is global references to modules/classes/functions. For example, in Python you may write:

  import my_module
  
  foo = my_module.Foo(some_arg)
So, if you wanted to find the definition of that my_module.Foo() reference, it's easy: go to the definition of my_module and search for the Foo class/function definition.

In Ruby, you may see instead something like:

  require 'my_module'
  
  foo = MyModule::Foo.new(some_arg)
Which looks very similar to Python, with the difference that the `require` method doesn't assign any local binding, but just executes the file my_module, which in turn will modify the global namespace directly and make `MyModule` available at runtime. The `require 'my_module'` might not even be present on the file that's then using `MyModule`: it might be indirectly required by another module that this file uses. Or, in the case of using Rails or any framework with auto-imports, the file might not have any `require` calls at all!

So, how is this resolved?

By convention, basically. If you see a reference like `MyModule::Foo` and want to see the definition of that, the convention is that that definition will live under my_module/foo.rb, so you can go to that file with some confidence that you'll find the the code for that class there.

So, if the convention is strong, and people follow it, this is basically a non-issue, and the go-to-definition can be done as easily as in Python, with or without an intelligent IDE.

---

The second case is when you have a dynamic reference to an object/function/whatever, like:

  def do_something(arg):
    arg.foobar()
In this case, neither Ruby nor Python (or any dynamic language in general) will help you much in trying to find the definition of the `foobar` method, as the type of the argument will only be known at runtime at the moment that this function will be called, and can even vary between calls.

There are different ways to make this go-to-definition somewhat more ergonomic than a global search for `def foobar`. But on the language level, i think both Python and Ruby are basically the same in this case: not very helpful. We then compensate by using good naming conventions, type annotations/comments, or using powerful IDEs that analyze the code to make good guesses about who is calling what.

epidemian··on Our self imposed scarcity of nice places
> Subways, trams and buses will also kill them, that's just as dangerous.

Do you have any source for this? AFAIK it's not true. Trams and subways specifically kill way less people than cars, even though in many places they transport more people than cars do.

For buses, IDK, but i would be surprised if a single bus was twice as likely or more to kill a person than a car. And a single bus transports way more people than a car.

epidemian··on Why I Use Nim instead of Python for Data Processing
I think this is missing the point of the article.

Yes, you can implement a faster Python version, but notice also:

* This faster version is reading all the file into memory (except comment lines). The article mentions the data being 150MB, which should fit in memory, but for larger datasets, this approach would be unfeasible

* The faster version is actually delegating a lot of work to Python's C internals by using text.count('G'). All the internal looping and comparisons is done in C, while on the original version, goes through Python

So yes, you can definitely write faster Python by delegating most of the work to C.

The point of the article is not about how to optimize Python, but about how given almost identical implementations in Python and Nim, Nim can outperform Python by 1 or 2 orders of magnitude without resorting to use C internals for basic things like looping or comparing characters.

epidemian··on The effects of remote work on collaboration among information workers
That's exactly the feeling that has most weighed down on me doing fully remote work: lack of connection.

And i mean with people. Doing software, i find it easy to feel somewhat "connected" to the work i'm doing because of the sort of immediate "it works / solves the problem" quality software usually has.

But with people, even though we're all on the same situation and we make our best effort to have some casual hangout time via zoom, i still feel it's too "formal" in a way, compared to the in-person experience of going to grab something to eat together, or just talking about semi-work-related stuff. And the resulting disconnection is not a great feeling really.

The other reply comment to yours sort of dismisses this as a generational thing or something. I don't think that's really the case. Even though i fall in the millennial generation, i've had my fair share talking on the phone with friends and family. In those cases, you don't need any further excuse to do so than just "wanting to talk". With coworkers, of course, firing up a zoom call just to talk about nothing in particular would feel completely awkward. The thing about sharing an actual physical space, i think, is that it creates opportunities for those informal conversations to happen naturally.

This is not to say remote work doesn't have its upsides; it definitely does. But we should not dismiss its downsides so readily.

epidemian··on Who's downloading pirated papers? Everyone (2016)
> why offering for free what others have the right to monetize should be considered okay.

Because having the possibility to monetize something doesn't make it inherently right to do so. People have monetized things that we would now consider abhorrent to do, like human lives in the form of slaves, wives as property, and countless examples of human rights violations.

Heck, even today in many places of the world people monetize access to education or health care for example, prohibiting some people from accessing things that are considered basic human rights. That they have a "right" to monetize it doesn't make it okay to do so.

I guess the underlying questions here is: should we consider access to scientific publications a right that anyone should be able to exercise? I personally think that yes, freedom of information is a laudable goal, and is definitely worth the inconvenience of losing some antiquated journals.

If you don't agree, what do you think would be the issue with having universal access to scientific papers?

epidemian··on Who's downloading pirated papers? Everyone (2016)
> But if the answer is "no", I cannot see how that justifies you getting a copy without paying. Where else in life is that a valid option? "I'd love to have a snickers bar, but I don't want to pay a dollar for it, so I guess I just take it." Obviously, there are differences between that example and sci-hub but for the core of the issue, these differences are negligible in my opinion.

I think the differences are definitely not negligible. There are similarities on the surface, yes, but one can distinguish between the two cases by asking "would it be OK if everyone did this?"

Basically Kant's categorical imperative:

> Act only according to that maxim whereby you can, at the same time, will that it should become a universal law

In the case of stealing snickers, we can imagine that if everyone did so, then making or selling snickers would no longer be a profitable business, so in the end snickers would no longer be produced, and we would all be worse for it :(

On the other hand, if everyone were to pirate scientific papers, no economic harm would come to the scientists doing the research for those papers. Only the journals would risk going out of business if they don't adapt, and that would be (or could be; i'm not entirely sure) a good outcome, as it would incentivize a more open approach to science distribution and access :)

So, one can conclude that, despite the surface similarities, stealing snickers is morally wrong, while pirating scientific papers is not.

epidemian··on Chekhov's Gun
Linking to 5 tvtropes pages —5 possibly-very-deep rabbit holes— on a generally nonworking day? Truly diabolic :D
epidemian··on Clickbait is unreasonably effective [video]
I understood that he's been doing more clickbaity titles for the past year or two, but maybe i misunderstood.

For the first video about the wind powered vehicle, yes i agree. It was more of a story and spectacle than any actual information. Still quite entertaining i think, but maybe disappointing if you wanted to learn something, which is usually the spirit of the channel.

epidemian··on Clickbait is unreasonably effective [video]
Have you also found other videos by the author to be "10 minutes of tiddly little bits of information"?

I think Veritasium makes some of the most valuable and informative videos out there. Definitely not the kind of channel that i would consider "baiting" with titles and then disappointing with the video content itself.

His views on video titles' "clickbaitiness", given the state of affairs of Youtube recommendation algorithms and the "competition" for viewers' attention, seem pretty on point to me.

epidemian··on Pyret Programming Language
My guess is that you didn't try @skrishnamurthi suggestion:

> Did you try the `sin(pi / 6)` example? You'll find that Pyret produces a rather interesting result that is also instructive.

The result of this doesn't feel like magic and doesn't resemble "JavaScript's truthiness and type coersion" at all IMO.

Here's a live code editor where you can try it out: https://code.pyret.org/editor

I found it to be a very refreshing and intuitively-guiding experience :)

---

Spoiler alert!

So, fist i had to find how to access pi and sin(), which was simple enough googling for documentation. Typing `num-sin(PI / 6)` on he editor already gives an interesting result:

  ~0.49999999999999994
That ~ there looks suspicious!

Then i tried `num-sin(PI / 6) == 1 / 2`, which seems to be syntactically invalid and yields an awesome error message:

  Reading this expression errored:
  
  num-sin(PI / 6) == 1 / 2
  
  The == and / operations are at the same grouping level. Add parentheses to group the operations, and make the order of operations clear.
Kudos to the Pyret team for such a nice error message!

So finally, adding those missing parens, `num-sin(PI / 6) == (1 / 2)`, yields another informative and useful error message:

  Attempted to compare a Roughnum to an Exactnum for equality, which is not allowed:
  
  The left side was:
  
  ~0.49999999999999994
  
  The right side was:
  
  0.5
  
  Consider using the within function to compare them instead.
All in all, i'm very impressed with the clarity and approachability of the language. Thanks @skrishnamurthi for the suggestion of trying this out! :D
epidemian··on Messaging and chat control
I'm not sure if this comment was troll bait; i'm going to reply as if it weren't.

> if they want to be xenophobic, what's the problem?

One of the problems is that even if the majority of people within a country are xenophobic and they get to decide the lays on a majority basis, there will still be people form other countries living there, or people who in general will be disadvantaged by xenophobic laws.

It's nice for laws to not be dictated only by a majority, but by a plurality. Instead of thinking "what benefits >50% of people is the right thing" we can think "what benefits the most people, including minorities", or "what avoids hurting the most people" to be the right things :)

epidemian··on JavaScript Is Weird
> Interestingly, Python does the same thing as JS in this case, even though it is typically quite strongly typed. [...] > Python outputs 0, it doesn't complain like the other two.

yep, this is one of those Python weird bits. in Python, booleans are ints, True is 1 and 0 is False. and i don't mean it in a JS-ish way like "they can be converted to...". no, True is the integer value 1. in fact, the type bool is a subtype of int. if you think of types as sets of values, and subtypes as subsets of their parent set, that `book < int` relation suddenly makes a lot of sense ;)

  >>> +(not not [])
  0
  >>> (not not [])
  False
  >>> 0 == False
  True
  >>> 1 == True
  True
  >>> True + True
  2
  >>> True - False + True * 0.5
  1.5
  >>> isinstance(False, bool)
  True
  >>> isinstance(False, int)
  True
  >>> bool < int
  True
so, if you accept that the operation `not []` makes sense to be defined as True (because `bool([])` is False), and that it makes sense for False to be the integer 0, then `+(not not [])` being 0 is just a logical consequence of that :)

for the record, i do think it's weird for Python to define bools as ints, and to make all values define a boolean semantics via __bool__().

epidemian··on JavaScript Is Weird
you're right in both points technically, but if that means that somehow these things don't make JS "weird" for people to learn/program, then i disagree

> that's a floating point problem. Plenty of languages will have the same issue.

yes, many (most) other languages do have the same floating point issues, but that doesn't make them less weird. JS numbers are IEEE floating point numbers, therefore floating point issues/weirdness are also JS issues/weirdness :)

> Calling these things weird is fair enough but I can't help thinking this is code you'd never actually write outside of the context of a "Look how weird JS is!" post.

the verbatim code snippets in particular, yes, you're completely right. but the underlying problems that these snippets exemplify are still there on actual "real" running code. they just look less suspicious on the surface.

> Just be moderately careful about casting things from one data type to another and all these problems go away.

true. but still, these things can happen, and when they happen, they tend to sneakily manifest as weird UI bugs, like rendering "NaN" or "undefined" on the screen (we have all seen those... there's plenty of meme images about them too), instead of noisily breaking with an exception, which is way more noticeable and actionable for us programmers when doing introducing these bugs in the first place hehe.

it's true that they are not the most common kind of bugs, i'll give you that, but when they happen, they can be incredibly frustrating in my experience, because you may only realize after they have been affecting user for a looong time (maybe years), but you just didn't know because JS decided it was a good idea to carry on after one of these nonsense operations like adding an array to a number, giving you nonsense results instead of useful (runtime) type errors.

story time!

i remember an ugly case of this which involved some search filters on a big-ish system. the JS code was quite generic in how it handled filters, and looked fine. for some time, all filters were single-value, as simple strings, but at some point the system started handling multi-value filters, which were encoded as arrays of strings. well, the programmers who implemented the UI for multi-valued filters just tried sending array of strings as filters to the existing filtering system, and it seemed to work correctly in the results it yielded, so they assumed the code was prepared for that too (it looked generic enough), and so they shipped the feature that way.

it was only years later, when i was porting some of that code to typescript, that typescript complained about invalid type operations. i was converting between languages pretty willy-nilly and assuming the existing system worked correctly, so i suspected typescript was being dumb with that type error. but no, it was actually complaining about an actual bug. when passing arrays of strings as filters, the underlying filtering system was at some point coercing those arrays to strings by accident. so ['apples', 'oranges'] became 'apple,oranges'.

the search results were always right when the multi-valued filters had only one value (because ['apples'] coerced to string is 'apples') and kinda right in some naive cases of multi-valued filters (because of how the text search engine worked), which was probably why the original programmers thought it was working correctly and didn't give it much more though or more thorough testing. but the search results were definitely not correct in most non-naive cases of multi-valued filters.

so our users had been affected by this bug of multi-value search filters basically not working for years, and we only discovered it by accident when porting some of the JS code to typescript because typescript was kind enough to tell us about this nonsense operation statically, without having to even run the code. i wish that JS were also kind enough to complain about these nonsense operations, albeit at runtime. it would have made this problem obvious from the get go, and would have prevented the original programmers from shipping a broken feature to thousands of users.

plot twist: although the story may make it seem that i was the competent programmer that figured it all out when porting the code to typescript, in reality "the original programmers" also included me (probably, i don't remember really), just some time before the typescript port :/

epidemian··on AMP pages no longer get preferential treatment in Google search
there's also this browser extension to always do that with reddit links, being logged in or not: https://addons.mozilla.org/en-US/firefox/addon/old-reddit-re...
epidemian··on Faster CPython Ideas – Issue Tracker for Faster CPython Project
JS have been heavily optimized by browser vendors, fueled by the intense competition on the browser space, and the huge resources invested by companies like Google.

IIRC Firefox 3 was the first browser to have what we would call a modern JS engine, with heavy emphasis on JIT compiling. Google Chrome soon followed and V8 dominated the JS perf story.

Python doesn't have such fierce competition of implementations. And besides, it has the "escape hatch" of being able to implement performance-critical code paths as C extensions, which is what heavy-lifting libraries like numpy do.

epidemian··on Gnome 40
I wish things worked worked like that. That users could actually tell you exactly what would make their lives easier. Even more: that they would go ahead and implement those things themselves!

Good software design encompasses listening to and talking with users, and actually discovering what they need, where their pain points are, etc. They won't tell you explicitly.

Apart from being a software developer, i'm also a user of course. I use GNOME every day, and even though i'm affected by this, i haven't found the time, patience and dedication to actually go and try to fix it. I understand that the GNOME developers might not have the time either. But it's not like this issue does not exist, or that it's not important.

And if i, and many people who see this as an issue and could potentially fix it, don't do it, then how can we expect that non-technical users would?

I have tried to teach my mother how to copy files between devices countless times in Windows. It's not an easy task for someone who hasn't grown using a computer. I'd love to advocate for more people to use Linux, but i won't, because each little thing like not being able to see the image whumbnails when picking files can be a road-blocker for non-technical people, and add up quickly.

epidemian··on CodeTour: VS Code extension to record and play guided walkthroughs of codebases
conversely, a screen recording does not allow for easy maintenance as this plugin does with its tours.
epidemian··on Self-supervised learning: The dark matter of intelligence
on one hand i agree with what you're saying. we humans have done terrible stuff like wars, genocides, famines, destruction of ecosystems, extinction of entire species, etc. and that's only the things we did more or less deliberately. we might cause our own extermination or a mass extinction event "by mistake", and we don't even understand how basic parts of our minds work.

but all of that being said, i think it's also worth considering what a non-human entity with more power than us might be able to do. after all, even the worst examples of humanity are confined to at most "only" causing millions of deaths, but not the eradication of all life on Earth for example. it's not difficult to imagine that a non-human entity, with non-human goals, and with super-human powers, might act in a way that is contrary to our interests, or even to our existence.

epidemian··on Using ES Modules in Node.js: A Practical Guide (Part 1)
There's an `import` statement with its custom syntax, which yes, does not allow anything else than a static string literal on the `from` part. But there's also an import() function, which is, well, just a function, so you can pass to it whatever parameter you want. For example a string computed dynamically as in your example. The linked page in my comment has a couple of examples of that function.
epidemian··on Using ES Modules in Node.js: A Practical Guide (Part 1)
I'm not entirely sure since i've never done this, but i think you can use the dynamic import() function[1] and await all the import promises:

  const plugins = await Promise.all(pluginModules.map(p => import(p)))
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
epidemian··on The largest study to date on the genetic basis of sexuality (2019)
Ah, thanks for the elaborate answer. I think i see your point better now, and yes, it's definitely a more nuanced topic than just "is this OK or not?"

I guess my personal gripe with most arguments against freedom of sexual orientation is that they all seem axiomatic or circular. Like, "because it's bad", "because it's anti-natural", "because this god says so", or some other chain of these that inevitably gets circular.

Your example comparison with religion seems on point, but also super thorny hehe. And since i'm not religious, it doesn't resonate too much either. Sorry.

I don't know if an analogy with musical preferences would be apt. Yes, it seems much more banal, but people also develop their identities around musical preferences sometimes, so it's not completely off!

And if, say, i was a metalhead, then, it wouldn't matter all that much if i've felt immutable love for metal all my life, or my preferences changed over time, or i chose it for some reason, or even if i love other styles! (maybe i'm extending this analogy too much) All that matters is that it doesn't harm other people. On the contrary: i'd share my love for metal with other metal lovers. Win-win.

Maybe it's a super dumb argument, but TBH that's kinda how i feel about sexual orientation or other important preferences. I just don't see the point in invalidating or not accepting other people's preferences and desires, as long as they are not harmful to others.

Thanks for the exchange, and i hope this wasn't too rambly!

epidemian··on The largest study to date on the genetic basis of sexuality (2019)
> The big question that this viewpoint misses is what to do with fears that certain things "turn people gay"

I think "the big question" some people still have is whether being gay is perfectly fine or not. If it is, then that question of things "turning people gay" is not so important. It's like asking if watching the Simpsons will make people like the Simpsons. Well yeah, it might, but there's nothing wrong with liking the Simpsons, so what's the problem?

Put into other words: thinking that having more gay people is a problem depends on thinking that being gay is problem in the first place, and that is the primary issue.

> and the flip side of that fear: that the straight community might use successful conversion therapy to eliminate the gay community.

Nobody will bat an eye if someone discovers they are straight after thinking they were gay. I don't know, maybe they saw one of the million heteronormative movies that are constantly produced and it somehow clicked on them; whatever, it's fine.

What is objectionable though, is to try to force someone into a given sexuality, instead of letting them be and discover their sexuality in their own terms.

epidemian··on Improving how we deploy GitHub
With large codebases maintained by many people, sometimes it's difficult to "just" do things like that. It's a bit weird to think that no one within that large group of professional developers hasn't thought of doing a simple obvious solution. It's probably not that simple.
epidemian··on I built a lay-down desk
And damage does not scale linearly. I'd much rather have 50 200g rocks falling on my head than a single 10kg rock :)
epidemian··on A Few Rules
I agree with you, but i dind't see the text you're quoting on the article. Was the article changed?
epidemian··on Scaling Erlang Developer Experience at WhatsApp [pdf]
There's this talk, The Sould of Erlang and Elixir, that opened my eyes to what makes this platform great:

https://youtu.be/JvBT4XBdoUE

It's not so much about what Erlang, as a language, "offers that Go does not". It's about the BEAM VM that runs it that makes all the difference.

I very much recommend watching the talk if you're interested in the topic :)

epidemian··on The use of `class` for things that should be simple free functions
Though i agree with with your general statement, i think the 1/10th the size figure is a bit disingenuous. At least the cases where i've gone from the unnecessary OO style to a simpler function/procedure based solution (in JS, which supports both styles just nice), the code size difference hasn't been anything that great. At most it's been half the size. Which is a lot i think! But not an order of magnitude less.

I'm noting this because i think that number kinda detracts from your main argument, with which i agree completely. I think even if the code would remain roughly the same size, the removal of OO would still be worth it, since, as you mention, is much less jargon and conceptual baggage. And if i can achieve the same result with a much simpler conceptual model and language, then all the better :)

epidemian··on How to Fix Slow Code in Ruby
Why do you consider Ruby to be inherently slow?

I don't see why that would be the case. In fact, the performance improvements during the 2.x era seem to indicate the contrary: that Ruby can be faster.

epidemian··on React Native for Windows and Mac
Yeah, but the thing is that it's just unnecessary.

isNaN() has been in the language forever. And in case you really need Number.isNaN() (because it's weird for isNaN('foo') to be true), it's been there for quite a long time too. Not enough to be on IE, sadly, but certainly more than enough to be on the modern JS engines React Native runs on.

So, at least for React Native, the package number-is-nan shouldn't be necessary at all. But it's probably a transitive dependency, and that's basically the problem with all these sort of polyfill packages: you might not need them, but a library that runs on older engines on which you depend (directly or transitively) does need them, so you end up paying the price anyway.

epidemian··on Pointermove event latency in web browsers
> I'm curious how that compares to what other people are seeing.

~10ms on Firefox, Linux, 60hz display.

← PreviousPage 4 of 14Next →