Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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:"directory/file").copy("new_path").copy("other_path")

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


Math helpers can be replaced with mixins:

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

class Integer
  include Math

  def initialize(value)
    @value = value

Call it like this:

In case you still need some helpers:

module Helpers
  # Some block of codes

class Object
  include Helpers

And now it's accessible everywhere.

To add more helpers, just modify the Helpers module:

module Helpers
  # Add more helpers

We can create factory class instead of named constructor:

class Lexer
  def initialize(source)
    @source = source

class LexerFactory
  def create_from_file(file)

  def create_from_string(string)

class Base
  def initialize(lexer_factory)
    @lexer_factory = lexer_factory

  def lexer

lexer ="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?

share|improve this question

closed as not constructive by Eric King, MichaelT, Frank Shearar, Steven A. Lowe, Bart van Ingen Schenau May 4 '13 at 7:55

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

This question looks similar to "why use an operator for addition if you can just use a function/method named add". I would say, go ahead and leave it out and see if you get into any real trouble or inconvenience. It is your language, so you can add them later on if you find you want them after all. – Bart van Ingen Schenau May 3 '13 at 17:53
If you have a class with no variables or methods...what do your classes do? – Jonathan Rich May 3 '13 at 17:59
fully Object-oriented (no statics, no globals, no class variables, no class methods) <-- This doesn't make any sense at all.. It's like saying "a car without wheels, doors, windows, or a gas peddle", that's a rock, not a car. – Jimmy Hoffa May 3 '13 at 18:04
How would you implement singleton without statics? – svick May 3 '13 at 18:19
Design your language, on paper. Use your language to solve real world problems, again on paper. After you've actually used your language a couple of dozen times, go and develop your language. Otherwise, you're reinventing PHP. – Gilbert Le Blanc May 3 '13 at 19:14
up vote 5 down vote accepted

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?

share|improve this answer
It is all just sugar, unless of course you're flipping switches on the front panel. But sugar sure does help the medicine go down more smoothly. – Robert Harvey May 3 '13 at 21:30
"If you try hard enough, you can program without nearly every single modern programming construct". That answer my question. Thanks. – random_guy May 4 '13 at 9:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.