9 ms·
One Way to Represent Things
- waynesonfire 6y agoI was thinking about something similar the other day when I was setting up a language server in my IDE for a non-mainstream programming language. What if there was a language we could develop APIs / libraries with that would automatically work with any other language / runtime? I guess I'm describing C interop, but that's too low level. C stands on it's own. I have no idea how to solve this but there would have to be some standard interface that the C interopt is developed against to provide additional context / metadata to allow more native interoperability. I don't know if I'm doing a good job explaining it. But, the idea is just like a language server. A server is implemented by a specific runtime and it can automatically interop with any client-library written in any other language, natively. This just sounds like wishful thinking.
- AndrewDucker 6y agoOn Windows this is called COM. A non-Microsoft equivalent would be CORBA.
- pogorniy 6y agoCheck https://github.com/oracle/graal https://github.com/oracle/graal. From readme: > GraalVM is a universal virtual machine for running applications written in JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Clojure, Kotlin, and LLVM-based languages such as C and C++. and yes, it can do interop between those languages
- amelius 6y agoCaveat: Graal is developed by a law firm who happens to have some software engineers on the payroll. Better not touch.
- schwartzworld 6y agoThere is something like that, a Unix shell. You can use the shell environment to string together small programs written in different languages. I mostly work in nodejs, and instead of connecting my things through language level bindings, I just write simple wrappers to call a child process and handle stdout and stderr. It might not work for all situations, but it means I can build my bits and pieces out of whatever language I want.
- TeMPOraL 6y agoI think the implicit desire of the parent is for the environment to handle data conversions for you. Unix shell is an unstructured text environment. Data loses all semantic context the moment it's pushed to stdout, and thus every program that wants to interact with it needs to have its own, half-baked, buggy parser included. This is wasteful and a source of many maintenance and security problems.
- schwartzworld 6y agoIt's not that hard if you just use common data formats. I don't have to reimplement a json or CSV parser in every language.
- TeMPOraL 6y agoNo, but someone else does. Every language comes with its own collection[0] of half-baked, bug ridden libraries for parsing JSON and CSV. JSON and CSV are particularly poor data formats, in that JSON has an impedance mismatch if the language you're using isn't JavaScript[1], and CSV means whatever the tool generating it think it means - it doesn't have to be comma, separated, or just values. Also, if you adopt either, you lose the benefit of human-readability, which is half of the justification for the UNIX tooling to emit plaintext in the first place. So one could as well bite the bullet and treat machine readability and human readability as separate concerns, and use formats suitable for each individually. -- [0] - It's never just one library. [1] - Do JSON objects get mapped to structs, arrays or hash tables in your language? How do you distinguish between true, false and null?
- MaxBarraclough 6y agoPerhaps none of this will be new to you, but here are my thoughts: It's challenging because of the mismatches that can arise between programming languages. We tend to use C as the lingua franca for communication between languages (i.e. foreign function interfacing, FFI), but it doesn't make the problem trivial. C++ has dynamic dispatch, whereas C doesn't. Java has garbage-collection, whereas C doesn't. Haskell has lazy evaluation. C# has async. Lots of things that can't be mapped across directly to C functions. FFI is by no means a neglected domain. Where it's possible to make it easy, it generally is easy. C++ written in a C style, can very easily interface with C. Same for Ada. The trouble is when there's mismatch from the more advanced features of C++/Ada that don't map that naturally to C. I don't think a 'language server' would really bring anything new to the table. Where that approach makes sense, we already have REST.
- galaxyLogic 6y agoWhat about Pure OOP? It has one way to represent things, everything is an Object. Details of the data-structures can be hidden behind the method-interface.
- Tomte 6y agoAnd everything has only one method in common: GetIdentifier(). So you've got components that cannot talk to each other, because the available methods differ (not just by name, but by what you can actually do), even though they are working on the same conceptual thing. The article argues for more "base datatypes" that are in common use. It doesn't matter whether the language/runtime exposes them as objects or PODs.
- galaxyLogic 6y agoThe "base datatypes" have to be accessed somehow. If you have base-type Array you have to access its elements somehow. In C-type language you would access the elements by calculating a memory-offset and reading that location in memory. The problem is that now your code depends on elements of Array being stored in memory in specific (relative) locations. Whereas in an Object Oriented language you would access the elements by calling a method myArray.at(123). The benefit is you don't need to know how that data is stored or where. In OOP the elements of an Array of course can be Arrays too, whose elements you can similarly only access via a method-call.
- choeger 6y agoThis doesn't help you to eliminate impossible values. A large aspect of datatype modeling is to encode constraints from the problem domain. Once encoded they are automatically enforced. Maybe the Builder pattern comes close to that ideal in OO, but it is really tedious to do right.
- stult 6y agoThis has been my experience as well. It can be extraordinarily difficult to design a consistent OO type system to represent things like quantities with units and references, alongside quantities with just units and neither units nor references. For example, altitude is a quantity plus a unit of distance plus a reference (eg above ground level). Except some references require different data to convert. So AGL requires elevation for conversion to mean sea level, for example. Designing an OO system to represent that and constrain against invalid operations gets super complex and the developer ergonomics rapidly degrade in most languages. I’ve only ever successfully done it in C#, and even then I’ve found maintaining the unit conversion code annoying.
- lmm 6y agoBeing able to build good representations of things is important. So many programming languages lack something as basic as sum types, which puts them behind the state of the art in the 1970s. Yes, Haskell has some fancier stuff in it as well, but a lot of the value comes from simply having a good way to represent "this or that" and applying it properly. The other thing that we do all the time in everyday life is a quotient, and as far as I know no programming language has a good way to represent that: something as basic as a fraction (i.e. a pair of integers, but two pairs are equivalent when ...) can't be expressed except in an ad-hoc way. I appreciate the author's enthusiasm for offering a large standard library of datatypes - I certainly think things like decimals and trees ought to be more available than they are - but I don't think we can even start on that until we actually have good tools for defining datatypes. And actually the best way to get there might be to have fewer built-in datatypes, and force ourselves to go through the work of defining numbers and strings and so on "in userspace", using the normal language facilities. That would quickly highlight a lot of quite basic things that a lot of languages are missing - e.g. literals for user-defined types are incredibly painful in a lot of algol-family languages.
- enriquto 6y ago> The other thing that we do all the time in everyday life is a quotient, and as far as I know no programming language has a good way to represent that: something as basic as a fraction How would the implementation of a general equivalence relation work? Just defining the equivalence relation does not yield a method for chosing a representative. Would you check the equivalence at each operation?
- hiker 6y agoIf the focus is on finite data structures only and the equivalence relation is "are the types isomorphic", then each type is isomorphic to the ordinary generating functor with some coefficients C : N->N: -- ogf(c,x) = Σ n:ℕ, cₙ xⁿ def ogf (c : ℕ → ℕ) (α : Type) := Σ n:ℕ, fin (c n) × (fin n → α) (fin n is finite type with exactly n elements) For example list has coefficients Cn = {1,1,1,1...} inductive list (α : Type) | nil : list | cons (hd : α) (tl : list) : list and binary trees inductive bin_tree (α : Type) | leaf : bin_tree | branch (x : α) (left : bin_tree) (right : bin_tree) : bin_tree have coefficients the Catalan numbers {1,1,2,5,14,42,132,429,...}. Computing those coefficients from a type definition is not always trivial though (see the symbolic method http://algo.inria.fr/flajolet/Publications/AnaCombi/book.pdf http://algo.inria.fr/flajolet/Publications/AnaCombi/book.pdf). This can be extended to infinite data structures too by switching the natural numbers to ordinal numbers in the ogf definition.
- d--b 6y ago100% agree. I think there is space for a programming language with first class support for typed tables. A blend of C# and SQL. F# with type providers does have some of that, or C# with linq, but in both cases, tables/relations are second-class citizen.
- _glass 6y agoSAP's ABAP has this. You have integrated SQL and just drop a select statement. A table's type can be used seamlessly: data products type table of comm_product. select * from comm_product into table @products.
- rurounijones 6y agoHaving had to use a bunch of different spatial packages, each defining their own `Position` type, I would love it if there were a standard type in the standard library or a very simple minimal "type only" package that they could all depend on. I could just pass between instead of having to covert constantly between the packages individual representations.
- TeMPOraL 6y agoThis connects to something I call "code bureaucracy" - in my experience working on legacy code, upwards of 50% of programming is being spent on shuffling data from one place to another, converting its type several times along the way, because different parts of the system - both internal and third party - each define their own version of same or similar types. I wish in particular we could reduce the number of equivalent types across libraries, but I feel the solution will have to involve tagging types with WikiData identifiers or equivalent. So "Color" becomes defined as type Q1075, or perhaps Q1075<Q166194> to show you mean an RGB-denoted color...
- saeranv 6y ago100% agree, having different point representations is a pain. I also don't like it when they're represented as objects (which is almost always the case). It seems so much more powerful, and expressive to me to just keep it as a tuple, so that you can work with matrices of points.
- pjmorris 6y ago"Representation is the essence of programming" - 'The Mythical Man Month', Fred Brooks.
- panic 6y agoThis makes me think of the Red programming language and its many builtin datatypes: https://github.com/red/docs/blob/master/en/datatypes.adoc https://github.com/red/docs/blob/master/en/datatypes.adoc
- nudpiedo 6y agoI thought that as well, many types highly tied and interconnected in a well designed type coercion system, and i think red is awesome as long as it is limited to a prototype, but for serious development it will soon fall short. But I didn’t spend much time with it.
- breck 6y agoThere is one way to represent things: tree notation. Or in other words: “space is all you need”. Everything can be encoded in a tree, from binary to this comment I’m righting now. There is a whole world of unexplored 2D and 3D languages that utilize space, and not 1D visible syntax delimiters to communicate meaning. It’s simple but a hard thing to communicate. However, seeing plenty of signs that it’s starting to catch on. Another way to think of it is that spreadsheets (1B users) and programming languages are about to meet and have a baby, and the result is going to be a leap across a chasm from the languages we have today.
- fctorial 6y agoSource code is actually n-dimensional. You only see a slice at a time because our screens are 2d.
- breck 6y agoDo you know of languages where parsing does not begin at position 0 and proceed linearly to position N? In certain designed 2D/3D languages you can have N parsers that start and end in different places in any direction, potentially even in a random order depending upon the language.
- carapace 6y ago> What if a simpler programming language had first-class representations of a lot more than strings and arrays? Red lang? > Where most languages have 6-8 base datatypes, Red has almost 50. https://github.com/red/docs/blob/master/en/datatypes.adoc https://github.com/red/docs/blob/master/en/datatypes.adoc
- carapace 6y agoTake something like the design discipline Scott Wlaschin describes in this talk "Domain Modeling Made Functional"[1]. Combine it with a catalog of standard models like David Hay's "Data Model Patterns: A Metadata Map"[2] which is like a Pattern Language for data models combined with a catalog covering most (enterprise) needs. Specify the binary formats with Erlang "bit syntax"[3]. Eh? [1] https://www.youtube.com/watch?v=Up7LcbGZFuo https://www.youtube.com/watch?v=Up7LcbGZFuo [2] https://www.sciencedirect.com/book/9780120887989/data-model-patterns https://www.sciencedirect.com/book/9780120887989/data-model-... [3] http://erlang.org/doc/programming_examples/bit_syntax.html http://erlang.org/doc/programming_examples/bit_syntax.html
- dwg 6y agoI appreciate the authors argument. On the other hand, isn't the reason there are not more first class data types is that they are so difficult to design general purpose? Even simple data types vary so much from language to language. It seems reasonable that this is why generalizing more abstract data types don't seem to catch on universally very often. It would be more convincing to see concrete examples, such as a type defined in a language such as Haskell that seems to be more or less universally applicable.
- slifin 6y agoAw I thought this would be an article about representing code in different ways, as text, as browsable namespaces etc
- imvetri 6y agoUse light and light based computing machine (or build virtually within the digital computer)
- Martinsos 6y agoI think there will always be a trade-off between "one way to do things" (opinionated approach) vs flexibility - the thing is, we need both, depending on the use case and the person using the language. But I do think we are falling behind with opinionated approaches. I am guessing that is because experts are usually the most prominent in communities, they are directing the ecosystem, and they prefer flexibility and power vs opinionated approach. Ruby on Rails was an opinionated approach made by non-expert that grew into something really big because of that. I am also trying to contribute in that direction with highly opinionated solution for web app development (https://wasp-lang.dev https://wasp-lang.dev).