News for hackers. Stuff that matters.
Re:Show HN: My weekend project - Codestagram by JoeCortopassi on Wednesday January 02, 2013 @11:40AM (#4997485)
I would love this idea, if it was limited to 10-20 lines. The forced conciseness of it would make devs focus on brief concepts and structure, rather than complex methods. It would end up being like Dribble rather than Gist/PasteBin, and be a great place to browse for techniques I hadn't previously encountered. Think about how fun it would be to scan through an Instagram style list of stuff like this:

############~C~#############

  if ((1?1:var)/2) {
      /* it's floating point */
  } else {
      /* it's an integer */
  }
#######~Objective-C~########

  + (NSString *) append:(id) first, ...
  {
      NSString * result = @"";
      id eachArg;
      va_list alist;

      if(first)
      {
          result = [result stringByAppendingString:first];
          va_start(alist, first);
          while (eachArg = va_arg(alist, id)) 
              result = [result stringByAppendingString:eachArg];
          va_end(alist);
      }

      return result;
  }
#########~PHP~##############

  $object = new StdClass;
  $object->foo = 'bar';
  echo json_encode($object);
############################

I know they aren't the best example, but I would love to be able to scan through a list of small code snippets (by language) that demonstrate concepts. On the plus side, it would be an easier way to show some competence in a language (for future employers) than having to do massive contributions to open source projects (don't have that much free time). The thing that makes or breaks this project is a smallish limit on lines. Without it, you are just another Gist/Pastebin, without the benefits of the wide user base and additional features. I have zero desire to chill at night and scan through a bunch of random 100+ line snippets that I have no context for, but I love goofing around on Stackoverflow, looking at fancy code snippets

Re:Show HN: My weekend project - Codestagram by imkevinxu on Wednesday January 02, 2013 @03:23PM (#4999031)
I feel like I found what you are looking for from Coderwall's blogs, they tend to be short interesting snippets by language and sorted by popularity.

https://coderwall.com/n/python https://coderwall.com/n/ruby https://coderwall.com/n/haskell

Re:Show HN: My weekend project - Codestagram by randomdrake on Wednesday January 02, 2013 @05:00PM (#4999571)
Hyperpolyglot has some of this stuff. It doesn't provide particularly rich and deep examples, but it is an easily scannable list of small code snippets. If you haven't seen it already, you should take a look.

http://hyperpolyglot.org/scripting

Re:Show HN: My weekend project - Codestagram by xxpor on Wednesday January 02, 2013 @04:13PM (#4999347)
Quick question: wouldn't 1?1:var always return 1?
Re:Show HN: My weekend project - Codestagram by JoeCortopassi on Wednesday January 02, 2013 @04:58PM (#4999558)
Nope. Having '1' as the condition in the ternary operator, causes 'var' to never be evaluated (to avoid accidental operations with getters and such), but the compiler allows the 'var' to affect if the '1' is treated as a float or an int. Here's a breakdown:

if var is a float...

  (1?1:var)/2
...becomes...

  (1.0/2)
...which equals 0.5 and is considered true when evaluated. But if var is an int...

  (1?1:var)/2
...becomes...

  (1/2)
...which equals 0 and is considered false when evaluated
Re:Show HN: My weekend project - Codestagram by Groxx on Friday January 04, 2013 @12:01AM (#5006345)
Is that part of the spec for coercions, or is it exploiting a typical compiler's behavior? It certainly doesn't appear to be a required way to process that statement (optimizations could remove the 'if' portion entirely), unless it is actually required of the compiler.