Giter Site home page Giter Site logo

oolib's Introduction

👑OOlib

license test contributors stars

OOlib is currently work in progress🔥

🗺Overview

OOlib is a nimble package for object oriented programming.

📜Usage

class

import oolib

class Person:
  var
    name: string
    age = 0

let steve = Person.new(name = "Steve")
let tony = Person.new(name = "Tony", age = 30)

protocol

import oolib

protocol Readable:
  var text: string

protocol Writable:
  var text: string
  proc `text=`(value: string)

protocol Product:
  var price: int

protocol pub Writer:
  proc write(text: string)

class Book impl (Readable, Product):
  var
    text: string = ""
    price: int

class Diary impl (Readable, Writable, Product):
  var text {.initial.}: string = ""
  var price: int
  proc `text=`(value: string) =
    self.text = value

class HTMLWriter impl Writer:
  var writable: Writable
  proc write(text: string) =
    self.writable.text = text

✨Features

  • class macro
    • Automatic generation of constructor
    • self inserted in procedures
    • all routines (e.g., method, converter, template) with the only exception of macro
  • protocol macro
    • Provide an Kotlin-like interface
    • defining setter/getter

Changelog

See CHANGELOG

🥷Author

Twitter

License

Copyright © 2021 Neo [email protected] This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.

oolib's People

Contributors

ftsf avatar glassesneo avatar jiro4989 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

oolib's Issues

Class data constants

I would like to be able to store data per class.

import oolib


class A {.open.}:
  const className = "A"
  const speed = 10.0f

class B of A:
  const className = "B"
  const speed = 15.0f

var a = newA()
var b = newB()

check A.className == "A"
check B.className == "B"
check a.className == "A"
check b.className == "B"
check b.speed > a.speed

Named tuple implementation

  • Implement named tuple instead of Alias of tuple
class pub SomeTuple(tuple):
  var a: int
  var b: string
  proc f(num: int) =
    discard

This will be converted to below

type SomeTuple* = tuple
  a: int
  b: string

proc f(self: SomeTuple, num: int) =
  discard

create class macro

  • make it to parse modifiers around class name(e.g. pub, of)
  • make it to define member variables and procedures
  • make it to parse procedure types(e.g. proc, method)
  • make it to insert self as a first argument to proc

Refactor and style

  • Refactor and style the code
  • Add {.compileTime.} to procs only used at compile time
  • Write comments

idea: interface validation

Many people use interface as a design tool.
perhaps it is possible to use Nim's when compiles(...) feature
to expand something like checkImpl(myClass, ISomeInterface)
where ISomeInterface will be scanned (typetraits perhaps) for the public procs and fields, and then for each it will be checked in the (hidden by template) when compiles block. then we get a compiler error message, that this proc was not yet implemented.
What do you think of this idea? btw, very cool lib. just came across it!

Rewrite README

  • Make very bad English sentences in README better
  • Add description of new features

oolibpkg ディレクトリ名を oolib にリネームしてはどうか

提案

  • oolibpkg ディレクトリ名を oolib にリネームしてはどうか

理由

nimble install OOlib したところ、以下のWarningが表示されました。

Warning: Package 'oolib' has an incorrect structure. It should contain a single directory hierarchy for source files, named 'oolib', but file 'tmpl.nim' is in a directory named 'oolibpkg' instead. This will be an error in the future.
Hint: If 'oolibpkg' contains source files for building 'oolib', rename it to 'oolib'. Otherwise, prevent its installation by adding skipDirs = @["oolibpkg"] to the .nimble file.

警告:パッケージ 'oolib'の構造が正しくありません。 'oolib'という名前のソースファイル用の単一のディレクトリ階層が含まれている必要がありますが、ファイル 'tmpl.nim'は代わりに 'oolibpkg'という名前のディレクトリにあります。これは将来エラーになります。
ヒント:「oolibpkg」に「oolib」をビルドするためのソースファイルが含まれている場合は、名前を「oolib」に変更します。それ以外の場合は、.nimbleファイルにskipDirs = @ ["oolibpkg"]を追加して、インストールを防止します。

これは oolib の内部用モジュールが oolibpkg ディレクトリ配下に存在するため表示されています。

通常、Nimのパッケージは library として提供する場合、プロジェクト構造を以下のようにします

  1. src直下に パッケージ名.nim をエントリーポイントとして配置する
  2. パッケージ名.nim から参照する内部用モジュールは パッケージ名 ディレクトリ配下に配置する

参考: Project structure - nim-lang/nimble

パッケージ名pkg といった命名にするのは、Hybridなパッケージとして公開する場合に必要なアプローチでしたが、現在は解消していると思われます

参考: Hybrids - nim-lang/nimble

Improve tests

  • Increase tests
  • Fix settings of testament
  • Fix source if test fails

`dataclass`

  • Add == template for data class like Kotlin's dataclass

Protocol(Interface)

  • Create protocol
  • Support for proc, func
  • Support for variables
  • {.pProtocol.}

`protocol`

  • protocol
  • implementation protocol for class
  • private procedures as private fields for tuple

git tagを打って欲しい

提案

  • このリポジトリの最新の master に git tag v0.2.2 を打ってほしい
  • 以降、新バージョンが公開されるたびに git tag vX.X.X を打つようにしてほしい

※ 今より古いコミットについて、その当時のバージョンに合わせて git tag を打つまではしなくてよいと思います

理由

バージョン番号指定で nimble install ができないため

⟩ nimble install '[email protected]'
Downloading https://github.com/Glasses-Neo/OOlib using git
   Warning: Package 'oolib' has an incorrect structure. It should contain a single directory hierarchy for source files, named 'oolib', but file 'tmpl.nim' is in a directory named 'oolibpkg' instead. This will be an error in the future.
      Hint: If 'oolibpkg' contains source files for building 'oolib', rename it to 'oolib'. Otherwise, prevent its installation by adding `skipDirs = @["oolibpkg"]` to the .nimble file.
       Tip: 2 messages have been suppressed, use --verbose to show them.
     Error: Downloaded package's version does not satisfy requested version range: wanted 0.2.1 got 0.2.2.

正常にインストールできる場合は、以下のように出力されます。

⟩ nimble install '[email protected]'
Downloading https://github.com/c-blake/cligen.git using git
  Verifying dependencies for [email protected]
 Installing [email protected]
   Success: cligen installed successfully.

詳細

nimble でパッケージをバージョン指定してインストールする場合、バージョン情報はGitリポジトリのタグに基づいて判別されます。nimbleファイルのバージョン番号のみでは不足しています。

参考: Versions - nim-lang/nimble

このリポジトリはタグが振られていないため、最新版のインストールしかできない状態です。

参考

他の nimble パッケージでバージョン番号運用をしているパッケージを紹介します

Create examples directory

  • Modifiers of class head (e.g. pub, of, distinct)
  • proc, func, iterator, converter
  • Base method using method
  • template
  • Auto definition of constructor
  • Assistance with constructor definition

Support for `Option`

  • Support for Option
  • Set nil as default value to member variables of type Option

Refactor and style code

  • Refactor
  • Add documentation comments
  • Style code
  • Update tests
  • Update error msg
  • Add parameter constraints

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.