7 ms·
What kind of language ideas do you folks have? What would your fizzbuzz look like? I'm not sure I've ever seen a more readable compact fizzbuzz than this vers
by fouc 5y ago
What kind of language ideas do you folks have? What would your fizzbuzz look like?
I'm not sure I've ever seen a more readable compact fizzbuzz than this version in coffeescript
['fizz' unless i%3] + ['buzz' unless i%5] or i for i in [1..100]
- neysofu 5y agoThe usage of `unless` strikes me as unmaintainable and "smart", not in a good way tbh. The types are all other the places, too. What is it even doing exactly? Appending a string to a null value..?
- zamadatix 5y agoAs is it's just doing the first 100 iterations of fizzbuzz as either a number or text depending on the fizzbuzz step but not printing or saving anything. If you wrap it in a console.log() it'll create a 100 element array of objects which are the answer for fizzbuzz[index+1] and log them. All that said I've never been a fan of dynamically typed languages myself. Fast to make things in but difficult to reason about later.
- mhio 5y ago> Appending a string to a null value..? Appending a string to an undefined value, via array addition, which turns them into strings but doesn't turn null into 'null' or undefined into 'undefined'. It's a bit of a hack. `'a' + undefined === 'aundefined'` `[ 'a' ] + [ undefined ] === 'a'` Also the empty string '' evaluates to false. `[ undefined ] + [ undefined ] == ''` This is wat - https://archive.org/details/wat_destroyallsoftware https://archive.org/details/wat_destroyallsoftware
- rmetzler 5y ago// Generated by CoffeeScript 2.4.1 (function() { var i, j; for (i = j = 1; j <= 100; i = ++j) { [!(i % 3) ? 'fizz' : void 0] + [!(i % 5) ? 'buzz' : void 0] || i; } }).call(this);
- gwbas1c 5y agoI'd like a language that makes it easy to mock and dependency inject without doing anything special. IE, if in my business logic, I write "new Foo()", I'd like to be able to write a unit test where I say something like, "whenever I wrote 'new Foo()' swap in this mock object instead." Or, in a module that's an entry-point, I'd like to say, "whenever I wrote 'new Foo()' swap in this subclass instead." I've spent so much time refactoring to make code mocking and dependency-injectable.
- divs1210 5y agoClojure does something very much like this using the with-redefs [0] form. If you have a function like: (defn send-mail [receiver-ids title text] ...) You can mock it out in your tests like: (with-redefs [send-mail (fn [r-ids title text] (println r-ids title text))] ;; send-mail will just print ...) [0] https://clojuredocs.org/clojure.core/with-redefs https://clojuredocs.org/clojure.core/with-redefs
- riffraff 5y agoTake a look at newspeak (smalltalk-ish, it avoids global references enforcing each component to receive dependencies as arguments, i.e. it has DI builtin) and NesC (C with components, which are composed at build time). Neither is popular but they're pretty interesting!
- jnwatson 5y agoPython already has everything you need. The most important aspect is that you don't have to change your code to use it. https://docs.python.org/3/library/unittest.mock.html https://docs.python.org/3/library/unittest.mock.html
- gwbas1c 5y agoAnother "crazy" idea: I'd like the compiler to reformat code to match strict style conventions. Why? Sometimes there's no "right" style. Sometimes novices need training wheels. In the long run, style doesn't matter, but in big projects code is easier to read when style is consistent. It's also easier to onboard when code follows industry-standard styles. Would it be better when a language gently pushes everyone to the same style?
- zamadatix 5y agoIt's definitely been done before, Zig comes to mind immediately but I'm pretty sure it wasn't the first place I've seen it done first party.
- throwaway17_17 5y agoThat’s an idea I’ve been playing around with for my personal language. If I do decide to release it, I have a feeling there will be common style rules that will be required for any ‘library’ code (it would be like if C++ files had to meet google style guides to be posted to some central collection repo). I think the compiler could implement the conversion, but it could require a programmer supplied ‘translation’ file (like including Unicode to ASCII substitutions, or required macro unrolling to some language core set of language features). That would allow for anyone to keep there code formatted in the most logical way for them, but would allow for a common format for distribution. I would also think going the other way, from public style to private should be a possibility. I don’t know if I will ever actually put my personal language out for release, but I’ve had two acquaintances repeatedly tell me (along with several HN commenters) that I really should at least release some blog posts about the language. Currently it is just my daily driver for work related programming and it compiles to C++, C, or JavaScript.
- userbinator 5y agoIn other domains, that is called authoritarianism.
- nostrademons 5y agoThis has been a part of Go culture from the beginning. You avoid style conflicts because you just run everything through 'gofmt' before checking it in. It's slowly catching on in other languages, eg. Clang now has clang-format and IntelliJ can auto-reformat your code according to a rule config you set before each check-in.
- klyrs 5y ago> What kind of language ideas do you folks have? 1. That would be telling. 2. Apparently there's going to be a theme? So that might make whatever wacky language I've been mulling a bad fit. I'm rather curious about how that will play out
- pfraze 5y agoI would build around a constrained high-level concept. Something like actors, perhaps. It would be assembly-like, command-oriented. I would then build a visualization environment which shows what the actors are doing, possibly step-by-step. It would show them moving values between registers and buffers. It would show messages passing between actors. It would show new actors create and finished actors die and errors get dumped into the canvas. Your concept as an end-user would be that you're programming these automatons. You could clearly visualize what's occurring and debug control-flow or algorithmic issues by stepping through their movements. Maybe not a great idea in the long run, but if it was a weekend lang jam, that's what I'd do.
- abecedarius 5y agoYou might like https://en.wikipedia.org/wiki/ToonTalk https://en.wikipedia.org/wiki/ToonTalk
- D7x7w9pHnT 5y agoMy favourite FizzBuzz is in Haskell, I found it in this talk by Kevlin Henney[0], and looks like this: fizzes = cycle ["", "", "Fizz"] buzzes = cycle ["", "", "", "", "Buzzes"] words = zipWith (++) fizzes buzzes numbers = map show [1..] fizzbuzz = zipWith max words numbers Henney explains in detail in the video, but it makes use of lazy evaluation to create an infinite list of FizzBuzzes, and also uses no if statements. I find it intellectually exciting, but make no claims on readability [0]https://youtu.be/LueeMTTDePg?t=2891 https://youtu.be/LueeMTTDePg?t=2891
- jjnoakes 5y ago"max" seems like an odd choice. Wouldn't that start to fail at large numbers? Edit: Nevermind, max is lexicographic, not based on string length. Brain fart.
- D7x7w9pHnT 5y agoYes, that part is hacky. It's easy to write a short function to do the same thing explicitly but then you lose the concise charm
- rmetzler 5y agoThanks for explaining it!
- robocat 5y agoI think 0 should be a FizzBuzz? Also I'm not sure how that solution would work for negative numbers... Then again what is the right answer for 7i + 24? Corner cases duck!
- ijlx 5y agoI've never seen fizzbuzz defined in such a way that zero or negative numbers are part of the problem. Typically it is a counting game, starting at 1 and going up to some arbitrary value.
- D7x7w9pHnT 5y ago
- breck 5y agoGotta wait to see what the theme is, but I’m going to be building a 2D tree language (https://jtree.treenotation.org/designer/ https://jtree.treenotation.org/designer/). Probably with a spreadsheet IDE like https://youtu.be/0l2QWH-iV3k https://youtu.be/0l2QWH-iV3k
- nostrademons 5y agoMost of the languages ideas I have aren't focused around syntax these days, rather about automating some tedious part of programming. Two that have stuck with me for a few years now: 1.) A language for plumbing. Basically, this is a mini-language for defining data structures and how they're shipped around different devices and processed. Think of protobufs or Apache Avro, but also including functionality like conditionals & flow control, rich collection operations like map/filter/fold, account & device management libraries, and most importantly, an Actor-based syntax (somewhat like Erlang) where entities like "The user's iPhone" or "The user's smartwatch" or "the database" just exist like process handles, and you can send messages to and from any of them. It'd then compile down into idiomatic Swift/Kotlin/Java/C/SQL to run on appropriate machine, so that your UI code just includes a library and you don't need to rewrite all your data plumbing, serialization, and business logic for each client platform. 2.) A language where you literally can use machine learning like if-statements. Basically it'd have functionality to dump out a feature vector (an array-of-structs), visualize it in a Jupiter notebook, label it (or send it off to Mechanical Turk for labeling), and then feed the labeled data back into any of multiple classifier types for use in an if-statement. Once trained, the model and training data would be checked in as if they were source code, and could be attached to code and versioned the same way that an algorithm would be. You'd run your program in two modes: in training mode, the program executes as much of the code path it can until it gets to an untrained classifier, then dumps out the data for that and starts the labeling/training process to generate the trained model. In execution mode, it uses the generated models to actually make flow-control decisions. Doubtful I'll ever have time to implement either one of these, but at least at the moment, they're somewhat timely and don't have convenient solutions. I think syntax is basically a solved problem, and don't really care about it.
- blamestross 5y agoI'm dubious about the order of operations here.
- jnwatson 5y agoI think there's a lot of opportunity in the 2d domain, in both directions. You might have a picture represent a program, like Piet [1]. Or you might have a language specifically designed to show certain types of pictures, like TeX or Processing or more narrowly, PlantUML. Another area to explore is the distributed space. Perhaps a language with Kubernetes capabilities as first-class objects. 1. https://www.dangermouse.net/esoteric/piet.html https://www.dangermouse.net/esoteric/piet.html
- Doxin 5y agoPython can do it with similar compactness: [(("fizz" if not i%3 else "")+("buzz" if not i%5 else "")) or i for i in range(1, 101)] Gotta love list comprehensions.