4 ms·
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 comple
by JoeCortopassi 14y ago
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
- randomdrake 14y agoHyperpolyglot 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 http://hyperpolyglot.org/scripting
- imkevinxu 14y agoI 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/python https://coderwall.com/n/ruby https://coderwall.com/n/ruby https://coderwall.com/n/haskell https://coderwall.com/n/haskell
- xxpor 14y agoQuick question: wouldn't 1?1:var always return 1?
- JoeCortopassi 14y agoNope. 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
- Groxx 14y agoIs 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.