HNHacker News
TopNewBestAskShowJobs

sjolsen

390 karma · joined April 17, 2014

submissionscomments
sjolsen··on Templating in C
And its weakness is that those ways in which you can, you're practically required to use to accomplish anything interesting. You can't even perform formatted output without throwing the entire type system out the window.
sjolsen··on Templating in C
>C99 has variable length arrays

But they don't give C any power C++ doesn't have. In terms of expressive power, you have things like std::vector, and in terms of performance, everyone except MSVC supports VLAs in C++ anyway, and MSVC doesn't even support them in C.

>How do I play to its ABI compatiblity strengths? Because I have to keep wrapping all of it in extern "C" declaration in a large enough system.

That is playing to its ABI compatibility strengths. In how many other languages is binary compatibility so simple?

Regardless, no one said anything about ABI compatibility being one of C++'s strengths. The point was about using C++'s template system for, of all things, exactly what it was designed to do.

sjolsen··on Unix V5, OpenBSD, Plan 9, FreeBSD, and GNU Coreutils Implementations of Echo.c
>complexity itself is a sin

Complexity is inherent to any task in some degree. That complexity must be expressed in full in any program which performs that task correctly, whether in terms of language/library constructions or the ways in which those are combined. When the tools with which you implement a task (here, C and the core Unix API) are structured substantially differently than the high-level concepts of which that task is composed, there is additional complexity inherent to mapping those concepts.

In light of that, I don't understand what you mean by, "complexity itself is a sin," unless you're referring specifically to the strictly unnecessary complexity introduced by a sub-optimal mapping of high-level semantics to core constructs. I don't think that's the kind of complexity we're seeing here. I think we're seeing the complexity inherent to mapping shell-level semantics to C semantics and the semantics of the Unix API, specifically error-handling semantics.

I agree with jws that what this code demonstrates is that the core Unix API is difficult to use for writing precisely correct high-level programs, even ones as simple as echo. I feel that this is exactly why it's important that core high-level programs like echo encapsulate as much of the complexity of mapping to C as possible (that is, in the style of GNU rather than SysV): so that one can easily write reliable programs with high-level tools like the shell without worrying about that complexity.

sjolsen··on Lenovo Statement on Superfish
There's a big difference between Lenovo selling bloatware rights to an adware company and the NSA (or whoever) bugging some hard drives.

Is that spyware Windows-specific?

sjolsen··on Lenovo Statement on Superfish
In a company as big as Lenovo, I'd be kind of surprised if the person or persons who decide what bloatware to load onto the consumer image make any sort of hardware decisions.

There's also that this particular kind of compromise is basically inapplicable to hardware. What are they going to do, put a 3G radio in your laptop that broadcasts your "data" via the cell network to Belarus?

sjolsen··on Show HN: A Unixy approach to WebSockets
>For example, suppose you have a bunch of pid files in a directory, and you want to send all the associated processes a signal. What kind of data structure stream does your signal sending program accept?

What program? A single line of shell code would work fine. Kill itself only need take a pid, or an actual handle if Unix had sich a thing.

>What needs to be done to a bare number to convert it into the correct format?

If a "bare number" isn't the correct format, why would you have them at all?

>How do you re-structure plain text from individual files?

The whole idea is not to use plain text at all.

>Structure in streams seems to have suddenly added a whole lot of complexity and work, and for what?

Structuring your data doesn't add complexity; when you consider the hoops one jumps through to strip data of its structure at one end of a stream and reconstitute it at the other, it's really reducing it. It's only if you insist on also using unstructured representations that complexity is increased.

Of course, as long as Unixes and their shells only speak bytestreams and leave all structuring, even of program arguments, to individual programs, it's a moot point. He's still right aboutnit being a shitty design, though.

sjolsen··on Lisp as the Maxwell Equations of Software (2012)
>With that in mind, I would not want to learn a new language for every project I was a part of

Well, you have to. Every new project comes with its own vocabulary and semantics. You have to learn those whether they're expressed in terms of data/function abstractions or syntactic abstractions. Sometimes—perhaps less often than many Lisp programmers appreciate, but sometimes nonetheless—those new concepts are simply easier to understand when expressed syntactically.

>The majority of programmers cannot design a good language, and if Lisp gives them the opportunity to try then that's a BadThing™

There are many programmers (I say "many" because I haven't actually met most programmers, but "most" might be true, too) who cannot design good data abstractions. Would you consider that [your favorite "OO" language here] allows one to form data abstractions to be a "bad thing?"

sjolsen··on Filenames and Pathnames in Shell: How to Do It Correctly (2010)
>What can you structure with besides syntax?

At the interface level, nested navigable fields.

>Even data structures in memory have a (binary) syntax

No, they don't. Syntax is the expression of structure through the arrangement of the contents of a single sequence. Data structures as they are typically realized express structure through the relationships between several sequences.

sjolsen··on Filenames and Pathnames in Shell: How to Do It Correctly (2010)
The solution is actually pretty straightforward: don't do everything with text. The actual content you want to manipulate, sure, do that with text. But there's no good reason to structure with syntax except that that solution is compatible with even the most arcane computer interfaces.

How you replace syntax-based structuring is the hard part, but it's not impossible.

sjolsen··on Filenames and Pathnames in Shell: How to Do It Correctly (2010)
>Remember to test your patterns with a print statement first

ZSH has an option to expand globs onto the command line the first time you hit return, and issue the command the second. I don't remember what it is.

sjolsen··on Is your programming language unreasonable?
> You may have abstract types in which case equality should not be implicitly defined. You may also have codata types where you cannot merely compare "value containment" since it's no longer a concept. These are both important things which are sometimes called "objects" and shouldn't be eliminated from languages.

I think it's important to distinguish equality from equivalence. There are many cases (e.g., enumeration types) in which equality is a perfectly appropriate definition of equivalence; but there are also many cases (e.g., some codata types) in which equality is an inappropriate definition of equivalence. Therefore, equality-as-equivalence as default behaviour is probably a poor choice— though it should be easy to opt for that behaviour.

As for equality (i.e., intensional equality) itself, I think memberwise equality (or perhaps even equivalence?) is a perfectly reasonable definition. There are times when you really want to discriminate on object identity (in the storage-location sense), but you needn't restrict equality to object identity to allow that.

sjolsen··on Avoiding game crashes related to linked lists (2012)
>Most C++ hard core game developers don't even use the STL that comes with the language ... Why do you think they will even consider linking the huge Boost library with their game ?

Boost has libraries that address specific efficiency concerns like the one the article discusses; the standard library containers don't. You also don't link with the entire Boost library. You link with the components you use, which in the case of a library like intrusive/list is whichever member functions you use from each container instantiation you use. That's a static link, too.

But no, I don't really expect anyone who considers themselves a "hard core" programmer to consider using a library like Boost.

>Also, the use of templates is usually a big no - no for most game dev studios.

Do you have a specific example?

sjolsen··on Our arrays aren't (2005)
The STL is a product developed and maintained by SGI. If you look at the containers listed in the article and on the SGI page, you will see a different set than is present in the C++ standard library, especially if you discount the containers that weren't in the C++ standard library when the article was written.

Now, people often refer to the C++ standard library as the STL, but the author of the article was clearly confusing the STL itself with the standard library, not just the name.

sjolsen··on Avoiding game crashes related to linked lists (2012)
>Why not use boost intrusive lists?

Yeah, why not? "The implementation is complex" is not a sensible reason not to use them; it's the complexity of the API one should worry about, and it seems as simple as adding a link subobject. I wonder if the author of this article actually bothered to test the Boost implementation and its performance.

sjolsen··on Our arrays aren't (2005)
Nitpick: the STL is not standard C++. The containers in the standard library are listed at http://en.cppreference.com/w/cpp/container.
sjolsen··on Guy Steele Interviews John McCarthy, Father of Lisp (2009)
>The point, of course, is that trying to create "one macro to rule them all" is already wrongheaded. There shouldn't be one universal iteration construct.

I agree that MAPCAR et al. should be used when they're appropriate. They are, however, sometimes simply not, and it's important to be able to build code to handle those cases. You don't need LOOP for that, since you can always use TAGBODYs and GOs, but LOOP is almost certainly more appropriate, just as MAPCAR et al. are usually more appropriate than LOOP.

In other words, yes, there should be a universal iteration construct; there just shouldn't be only a universal iteration construct. There's nothing wrong with having multiple tools at different abstraction levels for the same group of tasks, and I'd argue that it's usually a good thing.

sjolsen··on Lisp: A Cult I Almost Joined (2005)
Have you ever personally tried to optimize a Lisp program? It isn't terribly difficult, as optimizing goes. You have full access to control flow as far down as goto, and you can use machine integers and arrays. Depending on the implementation, you may even be able to use explicit pointers.

Obviously it isn't any closer to modern hardware than C, but as far from the hardware as the high-level parts are, the low-level parts are pretty reasonably close.

sjolsen··on Lisp: A Cult I Almost Joined (2005)
>One disagreement I have is Lisp is definitely not designed for high performance. Any competent C programmer would find the suggestion laughable.

A competent programmer, C programmer or not, would realize that performance is far more a matter of how you write your programs than what language you write them in; as the saying goes, "You can write FORTRAN in any language."

Now, the original LISP was not designed for high performance, to my knowledge. Later vendor-specific Lisps, like those found on the Lisp machines, were, because they had to be. Modern Lisps like Scheme and Common Lisp capitalize on the designs and technologies of those Lisps. For example, SBCL contains a very powerful high-level optimizing compiler that is capable of folding common code patterns down to efficient, often statically-typed machine code; that compiler dates back to the 'eighties when it was part of CMUCL.

Anecdotally, I recently ported a C implementation of introsort to Common Lisp. After adding type declarations, SBCL produced code about that took about 50% longer to run than GCC's code. The generated machine code used scalar integers, immediate-element arrays, and no runtime generic function dispatch. The comparative slowness was a result of the fact that SBCL's assembly-level optimization (or what little it has) is much weaker than GCC's, not of the fact that the code was written in Lisp.

>less syntax just means messier code

Lisp doesn't really have less syntax than other languages; it has more regular syntax. Forms like LET still have their own syntaxes beyond the lexical syntax of lists. Now, seventeen levels of infix operator precedence, that makes code messy.

>Parentheses everywhere doesn't make a language good. Just harder to read

Parentheses don't make Lisp hard to read. Being unfamiliar with that style of code layout makes Lisp hard to read. Once you're accustomed to it, the parentheses become mostly background noise, much like C's semicolons or many languages' "$s." Indentation is far more important, again just like in C. Lisp has the advantage that properly laid-out code clearly visually reflects the evaluation hierarchy, which is more than can be said for a lot of infix code, especially when dealing with complex arithmetical expressions.

>The "macro system" which refers to the ability to perform arbitrary functions on arbitrary data, is not unique to lisp.

That is not at all what Lisp's macro system does, and while there are other languages which have similar macro systems to Lisp's, they're at least as niche.

>And in general, usually obfuscates code and makes debugging harder.

Macros, when used correctly, make code more clear, not less. In fact, I've seen this argument made about a lot of different features in a lot of different languages, and it seems to me that what it usually means is, "I don't really understand what that feature is designed for." It's like claiming operator overloading is bad because it lets you define "+" to do division, even though you can just as easily write a function named "add" that does division.

>Everything that you can do with macro's and Lisps's homogeneous syntax is achievable with similar constructs in other languages

I can write a Lisp macro named DEFINE-ENUM that essentially does the same as C's enum, but also establishes a mapping from enumeration values to names; then, I could do

    CL-USER> (define-enum color
               (red    7)
               (blue   23)
               (purple 30))
    COLOR
    CL-USER> purple
    30
    CL-USER> (enum-name 'color 30)
    PURPLE
How would you do that in C? It may be doable, but certainly not both general and easy. You're wading into the Turing tar-pit here.

>Programming languages where data and functions are delineated by design have clearer structure and organization

Lisp delineates functions from other data (on that note, you described Lisp as "untyped." Lisp is in fact strongly typed). It lets you treat code as data if you like, but again the structure and organization of a program is a matter of how you write it, not what language you use. It's true, though, that Lisp lets you use (sometimes radically) different organizational structures than languages like Algol and C, but again those structures are unclear mostly because they're unfamiliar, not because they're inherently convoluted.

>Additionally they allow the compiler or interpreter to optimize by design

Lisp gives the compiler more room to optimize than a language like C; the tradeoff is that you don't have a human optimizing the difference as a matter of course (e.g., choosing a concrete integer type). This can sometimes be a good thing, and sometimes it isn't.

>In the rare case it's useful to have a function become a data argument, there are usually accommodations in the language to do so

It's actually very often useful if you have a way of writing generic algorithms; this is why "functors" are common in C++ (especially with the advent of lambda expressions), but not so much in C.

sjolsen··on 0x40 Assembly Riddles
You can also have 1 GiB pages in 64-bit mode.
sjolsen··on C++ Filesystem Technical Specification approved by ISO
> It's the same issue with the existing standard POSIX API

It's only an "issue" if you look at this as being an attempt to create a be-all end-all API, and it isn't. Things like std::filesystem (and POSIX file APIs) are made not to replace the native APIs but to complement them. They exist to fill the need for cheap, simple auxiliary tools, not the need for high-performance tools.

In other words, std::filesystem doesn't exist to facilitate writing a high-performance whole-filesystem search engine. It exists to facilitate writing high-performance audio analysis tools, image manipulation libraries, funky customizable desktop widgets, or really any conceivable program which uses the filesystem, but never in a hot loop. It exists for the same reason std::string exists in spite of the fact that it would a terrible core data structure for a text editor. It exists for the same reason std::iostream exists even though you would have to be insane to try to write an HTTP engine with it. It exists because when you need to load up three 200-megabyte files to grab the input for an hour-long simulation, you don't care about an extra five milliseconds at startup as much as you care about dead-simple, reliable code. Or maybe you do, in which case you can still happily use the native API.

sjolsen··on Five Popular Myths about C++: Postscript
I have maintained C++ code that was poorly written, if that's what you're getting at, but I have yet to find myself maintaining C++ code that has been poorly written as a result of the design of the language.
sjolsen··on Five Popular Myths about C++: Postscript
> the language tries very hard to make sure you can't understand a piece of code out of context

The language goes out of its way to make it possible to write code that is understandable with as little context as possible; type deduction, lambdas, range-based for loops— all of these are tools for reducing the amount of context or number of contexts necessary to understand a portion of code.

The language also allows you to write code that requires an inordinate amount of context to understand, yes. So does C. Hell, so does every other programming language worth using. It's practically impossible to prevent such code from being written without totally crippling the language.

> You can't even know what your arithmetic operators do without knowing the includes and other context.

If you can see that the arguments to your arithmetic operators are numeric (and you should be able to tell without looking outside of function scope), you need no more context. If the arguments are of user-defined types, you need no more context than if a function named "plus" had been used instead of the function named "operator+." If that is not enough context to understand the code, you have a problem with someone choosing poor names for functions, which goes far beyond operator overloading. For example, sure, operator overloading allows for code like

    auto operator+ (string_t a, string_t b) {
        return a.length () - b.length ();
    }
but so what? User-defined functions allow for code like

    void uppercaseify (char* str) {
        unlink (str);
    }
but it would be patently absurd to blame the language for code like that.
sjolsen··on Legacy PC design misery (2009)
Was that through technical failing, or was the project just mismanaged into the ground like the Alpha? Or was it killed by AMD's backward-compatible 64-bit architecture?
sjolsen··on GPGPU Accelerates PostgreSQL
No AMD stuff. We just had a box with a couple of Xeons, a Xeon Phi, and a K20.
sjolsen··on GPGPU Accelerates PostgreSQL
> Getting the data to GPU and results back takes just too long

I was involved in a database research project recently, and this is exactly what we found: sure, GPGPUs and the like are much faster than CPUs for the right database queries, but the transfer overhead is so absolutely horrendous that it completely dwarfs any gains in execution time.

sjolsen··on A tiling window manager written in Rust
I'll second using Emacs as the primary graphical shell. It shouldn't really be surprising that it's good for that task, since the interface is (or so it seems to me) heavily influenced by Genera's X interface. If Emacs let you display an external program such as Firefox in a buffer, I'd as well do away with Openbox and just run Emacs.
sjolsen··on Random in the wild
> what you don't want are a bunch of knobs and dials. What you generally need is a guarantee that your RNG interface is feeding you data from the system secure random number generator

The two are not necessarily incompatible. The distributions in the C++ standard library are not married to the standard engines. You can quite straightforwardly write an engine that uses urandom internally and which is compatible with the standard distributions; see the last couple dozen lines of libc++'s random.cpp.

Now, whether there are instances where using a statistical adapter with cryptographically secure random numbers is appropriate is another question, and one which I am not qualified to answer. However, such adapters as std::uniform_int_distribution and std::independent_bits_engine, if it can be verified that they are implemented correctly (and that is admittedly a big "if"), would probably still be useful.

sjolsen··on Random in the wild
You are correct; and of course, any hardware-level behaviour is likely to be implementation defined. I should note that MSVC [1] guarantees "non-deterministic and cryptographically secure" behaviour; and that libc++ [2] uses the "cryptographically secure" rand_s [3] on Windows, NaCl on other platforms where NaCl is available, and /dev/urandom where it isn't.

[1] http://msdn.microsoft.com/en-us/library/bb982250.aspx

[2] https://github.com/llvm-mirror/libcxx/blob/master/src/random...

[3] http://msdn.microsoft.com/en-us/library/sxtz2fa8.aspx

sjolsen··on Random in the wild
This sort of code is one of the motivations behind improving the random number generation facilities available in C++. If you're using C++ or you're using C and have the option to link with C++, I strongly recommend looking at the random number library introduced in C++11 [1]. In addition to letting you specify a statistical distribution (including a proper uniform distribution for both integral and floating-point types), it lets you choose between various PRNG engines with various trade-offs. It also provides a way to source hardware entropy with which to seed an engine, and it's all pretty easy to use.

*[1] en.cppreference.com/w/cpp/numeric

sjolsen··on Why Lisp macros are cool, a Perl perspective (2005)
> that doesn't seem very true, either

Strictly, it isn't. The point isn't that there's no syntax, though; it's that there's very little syntax, compared to other languages (consider C++'s… what, 17 operator precedence levels? And the Turing-complete parser?).

The comma in ',var' and '((x 7))' are examples of Common Lisp's built-in syntax. The former is part of a shorthand notation[1] for injecting literal code into templates. The latter is part of the syntax of LET[2].

[1] http://www.lispworks.com/documentation/HyperSpec/Body/02_df....

[2] http://www.lispworks.com/documentation/HyperSpec/Body/03_aba...

← PreviousPage 4 of 6Next →