Live data from Hacker News

Search: .lenght - Github

github.com

71–80 of 106 posts

Re: Search: .lenght - Github

#71
post #36

My experience is more with languages that are typically compiled and would report this error as an error fairly early on, so the coder would correct it long before checking the code in. What's the trade-off by having "undefined" returned instead of having an error reported as soon as the code is loaded?

It prevents you from later defining a 'lenght' method and using it at runtime without a recompile.

For core methods like 'length', it seems silly to think that you'd want to redefine it. And indeed, it's usually counterproductive - that's why any experienced JavaScript dev will have coding conventions like "Don't muck with the prototypes of built-in objects."

But at the application layer, this can be really useful. Imagine you're adding a new field to a message deep in the storage system, and then you want to pass that along to a template in the rendered HTML. It's really useful to be able to do this without recompiling & restarting each individual server between the backend and the frontend, and just edit a few template files and have them automatically pick up any changes to backend data formats.

Ditto adding a new database column, if you're using an RDBMS - it's pretty handy to have your model objects instantly reflect the new field, instead of needing to manually add accessors to each of your model classes. Rails and Django are built on this principle.

Also, you have a versioning problem with statically-compiled code in a distributed system. Imagine that you add this new 'lenght' field to a backend message, and add it to the frontend, and they both compile & deploy. Now imagine that a message from an old backend hits a new frontend (it's not possible to upgrade a whole distributed system at once without downtime). What does the new frontend do with it? It needs a piece of data, but the backend had no idea that it had to provide that piece of data. The only thing it can do is return the equivalent of 'undefined'.

In C++/Java code, you usually deal with these by inventing frameworks. Google code, for example, is littered with

  if (msg.has_new_field()) {
    run_long_complicated_ui_display_routine(msg.new_field());
  } else {
    fall_back_to_old_behavior(msg.old_field());
  }
checks. If you use a more dynamic language like Python, you can use language mechanisms to represent undefined values or fields that are defined at runtime. If you use a static language, you're stuck mimicking them with hashmaps and null.

Re: Search: .lenght - Github

#73
post #45

Earlier quoted context omitted.

Ah, aggressive trailing whitespace removal. That I can completely get behind. I've already got command-s bound to a custom macro that strips trailing whitespace in TextMate for myself and my co-workers; but this would be an even more inclusive solution.

Fantastic. If you use vim, you should have this in your .vimrc: " Remove any trailing whitespace that is in the file autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif

I prefer using the vim-trailing-whitespace plugin and fixing it manually: https://github.com/bronson/vim-trailing-whitespace

Re: Search: .lenght - Github

#74
post #26

I remember seeing a Github bot a couple weeks ago that strips out whitespace and adds a .gitignore file to a repo (I also remember this really rubbing some people the wrong way). This search indicates that it would probably be useful to have a linter bot running on Github for all the popular languages. It would find syntax errors, common mispellings, and compilation issues, and then submit pull requests to fix the is…

I wrote that bot! https://github.com/Miserlou/WhitespaceBot Feel free to fork it to do whatever you want, that's why I made it.

in my 10-years old project, removing all trailing whitespace would produce a 1000+ lines commit, and make many contributors' lives harder.

so, thanks, but I'll keep my whitespace.

Re: Search: .lenght - Github

#75
post #26

I remember seeing a Github bot a couple weeks ago that strips out whitespace and adds a .gitignore file to a repo (I also remember this really rubbing some people the wrong way). This search indicates that it would probably be useful to have a linter bot running on Github for all the popular languages. It would find syntax errors, common mispellings, and compilation issues, and then submit pull requests to fix the is…

I wrote that bot! https://github.com/Miserlou/WhitespaceBot Feel free to fork it to do whatever you want, that's why I made it.

Is there any equivalent of the robots.txt standard for public code repositories? Being able to opt-in to certain bots might be helpful (opt-out being the default, of course).

Re: Search: .lenght - Github

#76
post #67
post #45

Earlier quoted context omitted.

Ah, aggressive trailing whitespace removal. That I can completely get behind. I've already got command-s bound to a custom macro that strips trailing whitespace in TextMate for myself and my co-workers; but this would be an even more inclusive solution.

I prefer to have my editor strip that whenever I save a file without any manual action.

I should clarify that command-s is the save command. My macro overrides the standard behavior.

Re: Search: .lenght - Github

#78
post #55

Even the search has a bug. The query is for ".lenght" but many of the highlighted results are just lenght without the dot.

Prob a reg exp so matches any char...

But then shouldn't the highlighted bit include the char in front? It's also case insensitive. I think it's trying to be clever.
Post reply on HN