News for hackers. Stuff that matters.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by timpark on Friday June 30, 2017 @03:09PM (#14673003)
Neat. I saw something like this recently in game form: Codeshapes http://teropa.info/codeshapes/
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by runeks on Friday June 30, 2017 @05:24PM (#14673685)
I'm getting the shape of a lot of license headers, from which I'm supposed to guess the language.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by waisbrot on Friday June 30, 2017 @03:45PM (#14673210)
This is better than the story link, I think. I found it impossible at first, but after a few rounds there were some clear clues like the block of imports at the top of a Java file or the distinctive shape of functions in functional languages.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by rosstex on Friday June 30, 2017 @07:20PM (#14674154)
Wow, I'm way better at this than I imagined.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by otto_ortega on Friday June 30, 2017 @08:23PM (#14674470)
Interesting project, but these silhouettes reflect the programmer's coding style not anything specific to the languages themselves.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by justinian on Friday June 30, 2017 @10:33PM (#14675023)
The interesting thing here would be seeing some form of aggregation of various projects to see what effects the language does have on style. Would love to see something that shows the effect of e.g. Python's whitespace or Go's boilerplate.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by kevlar1818 on Friday June 30, 2017 @11:09PM (#14675143)
What immediately strikes me is Python's consistently high density compared to the other languages. This is something I've noticed before with well-written Python code; one can write powerful code in very compact blocks/paragraphs/stanzas/insert-metaphor-of-your-choosing.

Of course, take this with a grain of salt. This is a bit of an apples to oranges comparison, given it's just one file from one repo for each language.

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by sillysaurus3 on Friday June 30, 2017 @03:20PM (#14673055)
It's striking how easily you can see the repetition most languages force on you. PHP's sawtooth silhouette is especially interesting.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by otto_ortega on Friday June 30, 2017 @08:23PM (#14674473)
These silhouettes reflect the programmer's coding style not anything specific to the languages themselves...
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by Stratoscope on Friday June 30, 2017 @04:47PM (#14673512)
This is fun and interesting, but I don't think it says much about the various languages. Each of these languages can be formatted in a variety of styles.

As one example, Rust, and especially Servo, began with a recommended (or mandated) style with a heavy use of column alignment for things like function arguments. Like this code from rustfmt:

    let mut rewrites = try_opt!(subexpr_list.iter()
                                            .rev()
                                            .map(|e| {
                                                rewrite_chain_expr(e,
                                                                   total_span,
                                                                   context,
                                                                   max_width,
                                                                   indent)
                                            })
                                            .collect::<Option<Vec<_>>>());
But the Rust example in the silhouette page doesn't follow this style at all. Instead, it uses a purely indentation-based style with little or no use of column alignment. From looking at the latest Rust coding style document, it seems that the Rust community may be moving away from this aligned style to an indented style. (Anyone who is more tuned into Rust style, feel free to set me straight.)

If the code above were written in an indented style it might look more like this:

    let mut rewrites = try_opt!(
        subexpr_list
            .iter()
            .rev()
            .map( |e| {
                rewrite_chain_expr( e, total_span, context, max_width, indent )
            })
            .collect::<Option<Vec<_>>>()
    );
Same language, same code, but a very different silhouette.

Similarly, the last time I looked at the Oculus SDK, its C++ and C# code used a column alignment style, and I think some other projects like OpenCV use column alignment too.

Many other C++ and C# projects eschew alignment in favor of indentation, though.

This kind of choice in styles is available in all the languages being compared. Yes, even in Python. The Python example uses column alignment here and there, but it would be just as "Pythonic" to use indentation in those places.

So I don't think this is really comparing programming languages, it's just taking a single example for each language, where other projects in the same language may have very different silhouettes.

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by steveklabnik on Friday June 30, 2017 @05:46PM (#14673779)
> (Anyone who is more tuned into Rust style, feel free to set me straight.)

Style team member here; you're absolutely right. We started with more visual indent but basically have switched entirely to block indent.

> it might look more like this:

This is how rustfmt would format this code, exactly.

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by z3t4 on Friday June 30, 2017 @05:08PM (#14673615)
im working on a auto formatting tool ... is there anyone here that enforce column alignment or have it in their style guide ?
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by OJFord on Saturday July 01, 2017 @05:12PM (#14679059)
For Rust? Are you aware of rustfmt?
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by jMyles on Friday June 30, 2017 @03:37PM (#14673156)
I think this might be more effective if there was some kind of emphasis on lines which contain nothing but tokens used to end control structures, such as } or });

Frankly, as is, I think that javascript looks more crisp and sane than it really is (although, as another commenter points out, jQuery might not be the best choice for the current style norms).

Also, the Python choice, while a very cool project, is very atypical of Python style. I suggest using one of the more complex modules from Twisted.

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by e0m on Friday June 30, 2017 @04:09PM (#14673345)
When I looked at this, my immediate reaction was how awful long the files are. A programming language's community should encourage smaller files that do one thing.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by z3t4 on Friday June 30, 2017 @04:39PM (#14673486)
i like large files, it makes it so much easier to read the code, figure out what it does, find stuff, and refactor. i like it when the entire program is just one file, except for the modules source. i hate when there are 10000 files all containing 5-10 imports and then just one or two lines of logic. or worse; include files within include files several levels deep that all touch global variables. my idea of good abstractions is to only lift out code that has no couplings and no shared logic with the program, like modules that can be reused by other people in other programs.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by panic on Friday June 30, 2017 @06:33PM (#14673959)
The files are long on purpose -- as the article says: The code samples where chosen by finding popular repos for each language and using the longest file in each repository.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by Stratoscope on Friday June 30, 2017 @04:59PM (#14673575)
One of the examples is the jQuery source code, but the long file shown isn't the actual source. The real source code is broken up into a number of much smaller files, and the jquery-2.2.4.js file shown on the page is built from these smaller files.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by frou_dh on Saturday July 01, 2017 @03:21AM (#14675856)
Something that bugs me is, in languages that have a wrapping `namespace foo { ... }` sort of construct, the contents of that block being indented.

If, in a typical file, after the preamble at the top, you're giving ALL of the subsequent lines a minimum of 1 indent to the right... then what's the point of that 1 leading indent?

Just hug the left side. You don't need a constant visual reinforcement that you're a good kid who namespaces their declarations.

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by forinti on Friday June 30, 2017 @03:20PM (#14673057)
The fractal dimension of each one would be nice.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by codefined on Friday June 30, 2017 @03:38PM (#14673163)
For people who don't know about fractal dimensions, might I suggest this[0] video

[0] https://www.youtube.com/watch?v=gB9n2gHsHN4

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by andrepd on Friday June 30, 2017 @03:53PM (#14673252)
Fractal dimension? How so?
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by d--b on Saturday July 01, 2017 @05:35AM (#14676265)
What's most striking is that there is not a lot of differences between the languages. C and Python are somewhat denser and php tends to be more spread out. But that's about it.

I guess that reflects that humans break code in a way that looks the way they're used to.

Purely functional languages probably diverge significantly from these shapes.

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by azeirah on Saturday July 01, 2017 @08:56AM (#14676908)
It's a _very_ selective dataset, this doesn't show much. The idea's cool though
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by klez on Friday June 30, 2017 @07:17PM (#14674141)
I would be curious to see some functional languages examples, like scheme, Haskell and OCaml, for example.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by im_down_w_otp on Friday June 30, 2017 @10:07PM (#14674925)
Yeah, was thinking the same for Erlang since it incentivizes terse sections of hoisted functions.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by dpc_pw on Saturday July 01, 2017 @12:16AM (#14675361)
Shameless plug: a "Silhouette" (minimap) generator for command line: https://github.com/dpc/text-minimap
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by philsnow on Saturday July 01, 2017 @05:15AM (#14676211)
@lelandbatey: to see a difference that really pops, I suggest adding a common lisp or scheme silhouette, and a prolog one. Hell, if you can find a copy of gorilla.bas, do that too.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by abakus on Friday June 30, 2017 @03:13PM (#14673021)
Wait,Java has actually the shortest silhouette?
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by shawncplus on Friday June 30, 2017 @03:25PM (#14673086)
It's not as if they generated some "average" code to make an apples to apples comparison, they arbitrarily grabbed files with very different purposes based on length.

So really all this does is show that different code with different purposes has different shapes. AKA, pointless. You would have to do this across huge numbers of files and average them out to have anything actually interesting to look at.

Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by ricardobeat on Friday June 30, 2017 @03:32PM (#14673124)
jQuery is hardly a good benchmark for current js style. You'll find completely different shapes in other libraries.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by sillysaurus3 on Friday June 30, 2017 @03:33PM (#14673134)
JS is the new C++. It's several different languages depending on which subset you use: jQuery style, pyramid callbacks, promises, async/await, etc.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by z3t4 on Friday June 30, 2017 @05:24PM (#14673684)
always name your anonymous functions. that way it will be easier to break them out of the pyramid, make them testable, and easier to debug.
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by OJFord on Saturday July 01, 2017 @05:13PM (#14679066)
... and it will also make them not anonymous functions :)
Re:Show HN: Visualizing 'Silhouettes' of Programming Languages by z3t4 on Monday July 03, 2017 @05:18AM (#14686949)
A named "anonymous" function (lets call it lamda function to make it less confusing) is still a lamda function, but with a name ... It can not be called from elsewhere. So you get all the benefits from lamda functions! There's no advantage to not naming variables.

  var fs = require("fs");
  fs.readFile("somefile.txt", function readSomeFile(err, text) {
    if(err) throw err;
    else console.log(data);
  }