All Projects → krzysztofsroga → Solang

krzysztofsroga / Solang

Licence: apache-2.0
First fully featured programming language for Stack Overflow Driven Development

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Solang

Tcso
Try Catch Stack overflow (TcSo) Is a collection of Try statements in all the programming languages under the globe which catches the exception and searches for the cause of the caught exception in the stack overflow automatically.
Stars: ✭ 228 (+71.43%)
Mutual labels:  stackoverflow, programming
30-seconds-of-angular
Curated collection of Angular snippets that you can understand in 30 seconds or less
Stars: ✭ 24 (-81.95%)
Mutual labels:  snippets, programming
30-seconds-of-git
Short git snippets for all your development needs
Stars: ✭ 235 (+76.69%)
Mutual labels:  snippets, programming
30 Seconds Of Angular
[WIP] Curated collection of Angular snippets that you can understand in 30 seconds or less
Stars: ✭ 221 (+66.17%)
Mutual labels:  programming, snippets
Felix
The Felix Programming Language
Stars: ✭ 609 (+357.89%)
Mutual labels:  compiler, programming
30 Seconds Of Css
Short CSS code snippets for all your development needs
Stars: ✭ 14,945 (+11136.84%)
Mutual labels:  programming, snippets
30-seconds-of-csharp
Short C# code snippets for all your development needs
Stars: ✭ 132 (-0.75%)
Mutual labels:  snippets, programming
30-seconds-of-python
Short Python code snippets for all your development needs
Stars: ✭ 8,452 (+6254.89%)
Mutual labels:  snippets, programming
Nuitka
Nuitka is a Python compiler written in Python. It's fully compatible with Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, and 3.9. You feed it your Python app, it does a lot of clever things, and spits out an executable or extension module.
Stars: ✭ 6,173 (+4541.35%)
Mutual labels:  compiler, programming
30 Seconds Of React
Short React code snippets for all your development needs
Stars: ✭ 3,991 (+2900.75%)
Mutual labels:  programming, snippets
30 Seconds Of Php
Short PHP code snippets for all your development needs
Stars: ✭ 2,461 (+1750.38%)
Mutual labels:  programming, snippets
One
OneLang: The One System Programming Language. (release as soon)
Stars: ✭ 120 (-9.77%)
Mutual labels:  compiler, programming
Beginners C Program Examples
Simple, Short and Sweet beginners friendly C language programs
Stars: ✭ 138 (+3.76%)
Mutual labels:  programming, snippets
30 Seconds Of Code
Short JavaScript code snippets for all your development needs
Stars: ✭ 89,121 (+66908.27%)
Mutual labels:  programming, snippets
code-examples
Short code snippets written by our open source community!
Stars: ✭ 60 (-54.89%)
Mutual labels:  snippets, programming
Modiscript
Acche din aa gaye
Stars: ✭ 888 (+567.67%)
Mutual labels:  compiler, programming
Mcscript
A programming language for Minecraft Vanilla
Stars: ✭ 124 (-6.77%)
Mutual labels:  compiler, programming
Grain
The Grain compiler toolchain and CLI. Home of the modern web staple. 🌾
Stars: ✭ 2,199 (+1553.38%)
Mutual labels:  compiler
Jphp
JPHP - an implementation of PHP on Java VM
Stars: ✭ 1,665 (+1151.88%)
Mutual labels:  compiler
Codezilla
⚡️ codezilla ⚡️ One giant 🦖 collection of algorithms & design patterns.
Stars: ✭ 127 (-4.51%)
Mutual labels:  programming

So Lang? So what?

SoLang is an esoteric, example-centric programming language built on Kotlin DSL platform. It is based on an assumption that every program can be written using only code fetched from StackOverflow answers. The language allows developer to write extremely concise code by referencing snippets available online.

So what is SoLang and why should I use it?

  • It's built around Stack Overflow Driven Development process and brings it to the next level.
  • You don't ever need to write code which has been already written - just reference it!
  • Your code is always up to date - when someone update their answer on Stack Overflow, your code is automatically updated as well!
  • The code is usually more concise. Want to set-up a server with simple one-liner? That's the language for you!
  • You can write code which iterates over all solutions - find yourself the best one without copying and pasting code on and on again
  • Love writing malware? Well, now you can write one which no antivirus software will detect. Nobody expect downloading malicious code from Stact Overflow.
  • You can fully control compilation process with all features of kotlin programming language
  • Parallel code fetching and compilation (so that it doesn't take ages)
  • Answer caching - if you fetch different fragments of code from the same answer - don't worry, the data will be cached. Stack Exchange API will be called only once.

Example code

Hello World
fun main() = createCode {
    +StackOverflowSnippet(answerNumber = 1077349)
}.buildWith("python3", "script.py")
Another Hello World
fun main() = createCode {
    +StackOverflowSnippet(answerNumber = 11502683, codeBlockNumber = 2)
}.buildWith("cat", "hello.txt")
FizzBuzz
fun main() = createCode {
    +StackOverflowSnippet(answerNumber = 40427469, codeBlockNumber = 7)
}.buildWith("python2", "script.py")
FizzBuzz but up to 50 and completely skips not matching numbers
fun main() = createCode {
    +StackOverflowSnippet(answerNumber = 40427469, codeBlockNumber = 7) toLine 7 change ("101" to "51")
}.buildWith("python2", "script.py")
Create list of 1000 random dates, convert them to strings and then bubble-sort them
fun main() = createCode {
    +StackOverflowSnippet(answerNumber = 50165755) toLine 15 //declare randomdate
    +StackOverflowSnippet(answerNumber = 48980683, codeBlockNumber = 2) toLine 1 change ("random.random" to "randomTime") change ("x" to "my_list")  //generate list
    +StackOverflowSnippet(answerNumber = 902736, codeBlockNumber = 6) fromLine 3 change (">" to ">")//declare bubble and print sorted lits
}.buildWith("python2", "script.py")
Fetching specific answer revision
fun main() = createCode {
    SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.PRINT
    +SimpleSnippet("First revision:")
    +StackOverflowSnippet(answerNumber = 4362605, codeBlockNumber = 2, revisionNumber = 1)
    +SimpleSnippet("Second revision:")
    +StackOverflowSnippet(answerNumber = 4362605, codeBlockNumber = 2, revisionNumber = 2)
}.buildWith("python2", "script.py")

Installation

To try SoLang you can just clone the repository and build with gradle.

If you want to use SoLang in your own project, add it as a library to your build scripts:

build.gradle

repositories {
    maven{ url "https://jitpack.io" }
    maven{ url "https://kotlin.bintray.com/kotlinx" }
}

dependencies {
    implementation 'com.github.krzysztofsroga.solang:0.1.4-alpha'
}

build.gradle.kts

repositories {
    maven(url = "https://jitpack.io") 
    maven(url = "https://kotlin.bintray.com/kotlinx")
}

dependencies {
    implementation(group = "com.github.krzysztofsroga", name = "solang", version = "0.1.4-alpha")
}

Configuration

You can configure some basic features of SoLang compiler

// SAFE is default mode. You will be prompted if the code and build command are okay
SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.SAFE

// UNSAFE is dangerous. It executes the code without any prompt. 
SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.UNSAFE

// PRINT mode just shows you generated code and build command
SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.PRINT

Important notes

  • Without Stack Exchange API key you can download only 300 snippets every day. Snippets are downloaded every time you run your code. To compile more code get your token on on Stack Apps. See FAQ
  • To fulfill DRY principle, making copies of snippets is a little bit harder - every time you execute a method like toLine, change, the original snippet is modified. If you need the code in more than one place, please write a function.
  • Please, if you don't fetch specific revision of the answer, always use safe mode and verify it. It's because stack overflow answers can be changed. You probably don't want to see your computer executing rm -rf ~/.

FAQ

How to get StackExchange token / Downloading more than 300 snippets a day

To get an access token, simply authorize SoLang application with your StackExchange account
Just go to this link and log in to your stack account: SoLang App
This way you'll get a token which will expire after one day. If you need non-expiring token, click HERE
Your access token will be given in url of a page you're being redirected to.
Your token is here
Now you can use it in your application:

SoLangConfiguration.apiToken = "YOUR TOKEN"

The matching key is already embedded in the application. If apiToken string is set to anything but empty string, it will be used in requests.

I wish it could (...)

Just open an issue and we can talk about it.

Can I use it in production?

Well, it's not recommended, but as long as you fetch specific answer revision, it should work fine.

Why does it ask me if the code is okay before running it?

All of the answers on StackOverflow can be changed. If you want to disable this check Configuration

How many snippets can I download?

You can download 300 snippets a day without access token. You can download 10000 with it.
You may want to read: StackApss: Is there a limit of api requests?

How complex code can I create with it?

You tell me

Api Docs

Documentation is still being created, hence it may be lacking something.

Basic code structure

fun main() = createCode {
    //Your snippets go here
}.buildWith("command", "filename")

Function createCode takes a lambda with receiver CodeBuilder, returns SoCode

fun createCode(block: CodeBuilder.() -> Unit): SoCode

Method buildWith builds SoCode saves code to file and complies it using given command. Redirects program output to console.

fun SoCode.buildWith(buildScript: String, targetFile: String)

Creating snippets

SimpleSnippet just stores your code in unchanged form

class SimpleSnippet(code: String) : Snippet()

StackOverflowSnippet downloads given answer(and caches it in case other snippets would base on the same one), then cuts selected block number from it. In case you specified revision, all revisions are downloaded and then the one selected is used. In case no revision is specified, the newest one is used.

class StackOverflowSnippet(
    answerNumber: Int,
    codeBlockNumber: Int,
    revisionNumber: Int? = null
) : Snippet()

Adding snippets to your code

To add a snippet to code just mark it with + symbol. You can assign snippet to variable if you want

createCode {
    +SimpleSnippet("Hello world!") //this snippet is just appended
    val s = SimpleSnippet("Code in SoLang!")
    +s
    +s
}

This will result in output:

Hello world!
Code in SoLang!
Code in SoLang!

Modifying snippets

This section is being worked on... Stay tuned!
You can add modifiers to snippets. Modifiers are queued until code compilation and executed all at the same time.

Take care! When you modify a snippet, there isn't created a copy!

Experimental features

This section will be published in near future

Project Plans

Alpha TODOs

  • [x] Upload to Jitpack
  • [x] Memoize downloaded snippets MnemoniK
  • [x] Cleanup dependencies
  • [x] Add option to start code block numbering from 1
  • [x] Design Logo
  • [x] Start writing tests
  • [x] Safe mode which shows generated code before execution (well, answer can be edited... it isn't quite safe)
  • [x] Allow usage of specific answer version
  • [x] Api key usage
  • [x] Fix toLine after fromLine usage Let's say that's the intended behavior - if you cut fromLine first then line numeration for toLine changes. Hence snippet fromLine 4 toLine 8 is the same thing as snippet takeLines 4..11
  • [x] Fix all visibility modifiers

Beta TODOs

  • [ ] Web version with Kotlin Playground
  • [ ] Compilation server with Kotlin Web Demo
  • [ ] Analyze possibility of returning subclass of Snippet from SurroundingSnippet - not extending CodeBuilder, but creating its own
  • [ ] BuildScript class, build script fetching
  • [ ] Implement StackSort as one of the examples
  • [x] Downloading code from other Stack Exchange pages.
  • [ ] Infix fun parametrize / parametrizedWith
  • [x] Searching for answers and iterating over accepted ones
  • [ ] Caching data between runs

Stable Release TODOs

  • [ ] Callbacks from executed code
  • [ ] Real time code output and interaction (for some reason inheritIO does not work)
  • [ ] Downloading code from GitHub.
  • [ ] Full test coverage
  • [ ] Create add-ons for chrome and firefox.

Future plans

  • [ ] Allow self-referencing SoLang code on Stack Overflow. Sharing recursive snippet could be funny.
  • [ ] Write plugins for most popular IDEs and editors - it should show you hints how do your snippets look like.
  • [ ] Add support for plugins (other code sources).
  • [ ] Mixing programming languages in one project

Project History

  • 2019-03-28 - First commit
  • 2019-03-31 - First working version
  • 2019-04-01 - Making project public
Disclaimer: This is NOT official language created by Stack Overflow.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].