Is it possible to write a code without class methods, globals, and class variables? [closed]

I’m designing my own programming language for fun, and I’m thinking of making it fully Object-oriented (no statics, no globals, no class variables, no class methods), so I need to find a way to completely eliminate the needs of class methods, but, first, I need to make sure that I know all the problems that could only be solved by using class methods.

So, usually, class methods is used for creating helpers, and named constructors, yes? (Anything else?).

Currently, this is what I have to replace those with Object-oriented designs:

For example: the File helpers, I’m thinking of designing it like this:

class File
  def initialize(path)
    @path = path
  end

  def copy(destination)
    # Copy file from @path to destination
    # Then open destination path by creating new file instance
  end
end

I’m actually using C, but I wrote the example in Ruby so it will be easier to understand.

No class methods, and you could chain it like this:

File.new("directory/file").copy("new_path").copy("other_path")

If its too long, I could just drop the “new” method like what Python do:

File("directory/file").copy("new_path").copy("other_path")

Math helpers can be replaced with mixins:

module Math
  def pow(value)
    @value = @value ** value
  end
end

class Integer
  include Math

  def initialize(value)
    @value = value
  end
end

Call it like this:

Integer.new(100).pow(10).pow(10).pow(10)

In case you still need some helpers:

module Helpers
  # Some block of codes
end

class Object
  include Helpers
end

And now it’s accessible everywhere.

To add more helpers, just modify the Helpers module:

module Helpers
  # Add more helpers
end

We can create factory class instead of named constructor:

class Lexer
  def initialize(source)
    @source = source
  end
end

class LexerFactory
  def create_from_file(file)
    return Lexer.new(File.read(file))
  end

  def create_from_string(string)
    return Lexer.new(string)
  end
end

class Base
  def initialize(lexer_factory)
    @lexer_factory = lexer_factory
  end

  def lexer
    @lexer_factory
  end
end

lexer = Base.new(LexerFactory.new).lexer.create_from_file("directory/file")

So my questions is: What am I missing? What you can’t do without class methods, and class variables? What problems that could only be solved by using those?

12

Is it possible to create a programming language or write object-oriented code without static/class methods/variables? Absolutely. Case study: the Javascript programming language. The key insight is that, if you squint a bit and hold your head at an awkward language, classes start looking like objects. Special objects that do funny things when you poke them a certain way, sure, but objects nonetheless. Add in a prototype system (as Javascript does), and suddenly you have not only the standard approaches for object-oriented code reuse, but many others too. And all without special support for statics — instead, just add a field to your “class” (which is actually an object) and you have a static/class variable. Add a method to your “class” and you have a static/class method.

But what about globals? Well, I’m not exactly sure what you mean by globals, so let’s generalize and talk about free variables, or variables from some enclosing scope (including the global one, which is the “enclosing-est” scope there is 🙂 ). Can you imagine how hard it would be to write a program without free variables? It’s not fun 🙁 , but people have tried and succeeded, and you might find these articles interesting.

When you ask:

So my questions is: What am I missing? What you can’t do without class methods, and class variables? What problems that could only be solved by using those?

I think the real question you’re getting at is “what are the minimal constructs needed to create a Turing-complete programming language?” or possibly “what are the minimal constructs needed to create a practical programming language?”

Those kinds of questions are awfully difficult to answer. Like, PhD-worthy, which is why people spend their lives researching answers to them. Perhaps learning about formal systems of computation, such as a lambda calculus, would help you to understand these questions better. But ultimately, they’re slippery slope questions, and nearly impossible to answer when you throw practical considerations (so that real people can use it) into the mix. If you try hard enough, you can program without nearly every single modern programming construct — does that mean it’s all just sugar?

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật