Giter Site home page Giter Site logo

mubaris / yes Goto Github PK

View Code? Open in Web Editor NEW
86.0 7.0 42.0 101 KB

yes - Implementation of simple and dangerous yes command in various languages. :+1:

License: MIT License

C 4.08% C++ 2.75% Go 2.21% JavaScript 2.11% Python 1.73% Ruby 0.59% Java 2.08% Perl 0.48% Lua 0.53% Shell 50.66% Scala 0.82% Erlang 0.61% D 0.87% PHP 22.91% Rust 1.10% Swift 0.75% AppleScript 0.91% Brainfuck 0.70% C# 0.81% Objective-C 3.32%
linux terminal yes command-line multiple-languages

yes's Issues

BUILD_LASTEXIT is not cleared

When calling BUILD-FAIL, the BUILD_LASTEXIT variable is being set. However it is only cleared in BUILT and changed in BUILD-RUN.

This leads to a scenario where if after calling BUILD-FAIL the next language is missing a compiler this will not be indicated. It also messes the layout of the messages printed.

Example:

  1. Erlang fails with BUILD-FAIL "TODO BUILD SCRIPT".
  2. I don't have fish so case is not matched - it skips to BUILD-END
  3. Because BUILD-LASTEXIT is still set to "FAIL" it exits without printing anything.
BUILD-END() {
	# Fail command.
	if [ "${BUILD_LASTEXIT}" = "FAIL" ]; then
		return 0;
	fi
...

Implementations seem inefficient.

Most implementations seem a little bit inefficient, for example the Java version could be optimized to this:

class yes {
    public static void main (String[] args) {
        if (args.length == 0) {
            while (true) {
                System.out.println("y");
            }
        } else {
            String line = "";
            for (String arg : args) {
                line = line + arg + " ";
            }
            line = line.substring(0, line.length() - 1);
            
            while (true) {
                System.out.println(line);
            }
        }
    }
}

We first build the string which will be one line, and then simply dump that string into the output stream. This removes the need for the system to constantly parse "%s ", it also removes that trailing space from each line which shouldn't be there.

As a sidenote, yes, I could have used a StringBuilder, but opted against it for simplicity reasons and simply because the string, hopefully, never becomes that large to warrant a StringBuilder there.

The same applies to the C, Go, PHP, Python versions, and to a lesser extend to nearly all other versions, which are constantly looping over the arguments instead of caching the line once.

Files should have their build and execution instructions attached.

Each file should sport their build and execution instructions, ideally in the header as comments, maybe even required versions (for example the Java version requires Java 8).

That would allow every one to build and run every file, no matter if they are familiar with the toolchain or not. For some files, like the shell, it's as simple as executing the file, others, like the Java version, require a two step process (build and execute).

Missing languages in build script.

There are a couple languages that are missing in the build.sh script. If you know how to run/build any of the following languages, we would be thankful if you could help out and add it.

  • D
  • Erlang
  • Haskell
  • Lisp
  • Lua
  • Rust
  • Scala

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.