• Activity
  • Votes
  • Comments
  • New
  • All activity
  • Showing only topics with the tag "programming languages". Back to normal view
    1. Why store code as text files?

      Code is usually version controlled nowadays in git or some other VCS. These typically operate on text files and record the changes applied to the files over their history. One drawback from this...

      Code is usually version controlled nowadays in git or some other VCS. These typically operate on text files and record the changes applied to the files over their history. One drawback from this is that formatting of the code can introduce changesbto the files that make no semantic difference, e.g. newlines are added/removed, indentation is altered etc.

      Consistent formatting makes the code easier to read, but the style used is an aesthetic preference. There might be objective reasons for readability in at least the extreme cases, but in many cases the formatting is purely a preferred style.

      If we instead version controlled code in the form of an abstract syntax tree (AST) (possibly even as just a series of transformations on that tree), we could have any formatting we'd like! When editing the code we would just be changing a projection of the AST and when we've made our changes the transformations could be made to the stored AST. If two languages shared the same AST the choice of language even becomes a choice for the programmer. Sadly this has some limitations since ASTs are usually language specific... But we could possibly take this a step further.

      Could we take a compiled binary and use that as the basis for generating an AST? This is essentially what decompilers do. For heavily optimized code this is severely limited, but for debug builds a lot of extra information is retained in the binary that can be utilized to construct a sensible representation. This way of storing code the language used becomes a style preference! Code compiled from one language might become alien when viewed in another language (thinking of lazy Haskell code viewed in C), but maybe that is a corner case?

      There are issues when considering binaries for different platforms. A binary for the JVM isn't the same as one for ARM64 or one compiled to run on an x86. So there are some limitations there...

      One (very) good thing about storing code as text files is the ubiquity of software capable of viewing and editing text. It would however be cool if we could make programming language a stylistic preference that is compatible with other languages! At least the AST part should be perfectly achievable.

      16 votes
    2. Experience with Crystal programming language?

      I have heard just a little bit about the language Crystal every so often, probably since it was first mentioned on /r/programming. From what I know, it's Ruby-like syntax but with a static type...

      I have heard just a little bit about the language Crystal every so often, probably since it was first mentioned on /r/programming. From what I know, it's Ruby-like syntax but with a static type system, which seems like a big benefit to me.

      I written just a little bit of Ruby, so the syntax isn't very familiar to me, and I haven't bothered trying Crystal out, but I'm curious to know what kinds of things people do with it.

      So, my questions are: Do you have any experience with Crystal? If so, what have you used it for? Was it a professional or recreational project? How did you like it? What about it stood out to you compared to your experiences with other languages?

      Thanks!

      8 votes
    3. Programming Languages that are Both Interpretable and Compilable?

      I've been thinking about the feasibility of defining a language spec that can both be compiled and interpreted lately. I first thought about it while writing code in crystal, which, for the...

      I've been thinking about the feasibility of defining a language spec that can both be compiled and interpreted lately. I first thought about it while writing code in crystal, which, for the unfamiliar, is a compiled language based heavily off the syntax of an interpreted language (ruby).

      Here are a couple reasons I find the idea interesting:

      • It effectively neuters the interpreted/compiled language debates. Why just choose one, when both have such big upsides?
      • You could develop a program in the interpreter with the same playfulness as you get in a shell, and then compile it into a speedy 'lil thing!
      • It would be wonderful for metaprogramming! From my experience, languages usually define a little janked together syntax for compile-time execution. If the language had an interpreter for itself within the compiler, you could metaprogram and program in the exact same language.

      I'm curious if any languages like this exist, or if you can think of more benefits.

      Edit:
      I just want to mention that my reference to 'feasibility' earlier is not born of disbelief - you can write a compiler or interpreter for any (to the best of my knowledge!) well defined formal grammar with enough effort. I suppose I left that word there to account for the fact that I might have unknown unknowns here.

      14 votes