Skip to content

Using the patterns and particles of physics as the building blocks of programs

License

Notifications You must be signed in to change notification settings

EschelonAzha/VirtualPhysics

Repository files navigation

Unleash the Power of Virtual Physics: Build Software Like a Real Engineer

Virtual Physics isn't just a library. It's a paradigm shift. Imagine creating software governed by the same fundamental laws that shape the universe – a world where programs have gravity, energy, and even subatomic particles. Welcome to Virtual Physics, a revolutionary approach to software engineering that unlocks limitless possibilities.

Tired of unpredictable, unstable software? Traditional methods often leave us tangled in a web of complexity. Virtual Physics breaks free from these constraints, offering a structured, physics-inspired framework for building robust, reliable systems.

How Does It Work?

Virtual Physics provides a universal set of building blocks, just like the fundamental particles that make up everything in the real world. From protons and neutrons to gravity and energy, these essential elements translate into software concepts like objects, forces, and interactions. By harnessing these familiar patterns, we can engineer software with an unprecedented level of predictability and coherence.

The Benefits Are Clear:

  • Simplified design: Break down complex systems into manageable, interconnected components.
  • Enhanced stability: Leverage the laws of physics to build inherently robust and predictable software.
  • Intuitive understanding: Learn the language of Virtual Physics, and complex concepts become natural and familiar.
  • Universal foundation: Create diverse software architectures from a single set of core principles.

Virtual Physics Superpowers:

Effortless Data Transmission

Virtual Physics reimagines data transmission by drawing inspiration from the fundamental laws of physics. It introduces a unique approach that eliminates the need for traditional serialization formats like JSON or XML, resulting in efficient and precise data exchange.

Key Concepts

Atoms, Molecules, and Compounds:

  • Atoms represent individual data fields.
  • Molecules combine Atoms to create small structures.
  • Compounds are complex structures, akin to objects or collections.

Built-in Serialization and Deserialization

  • emit() function: Seamlessly converts Atoms, Molecules, and Compounds into compact "photon strings."
  • Absorber.materialize() function: Reconstructs the original object from a photon string.

Advantages

  • Compact Size: Photon strings are often 90% smaller than JSON or XML
  • Lossless Transmission: No class information is lost.
  • No External Dependencies: Eliminates the need for third-party serialization libraries.
  • Ease of Use: Serialization and deserialization require only a single line of code each.

Code Example

// Machine 1

val addressRec = AddressRec()
val emission = addressRec.emit()

// ... Transmit the emission to the other machine....

// Machine 2

val (clone, _) = Absorber.materialize(emission)
val addressRecClone = clone as AddressRec

Conclusion

Virtual Physics offers a powerful and innovative approach to data transmission, inspired by the laws of nature. Embrace these superpowers to streamline data exchange in your applications.

Virtual Physics Data Binding: Simplifying the Complex with Atomic Power

From a user's perspective, Virtual Physics works its magic at the atomic level. You don't need to delve into the intricate interactions of subatomic particles to harness the power packed within each "Atom." These fundamental building blocks of data, like their real-world counterparts, possess an innate ability to bind together. This opens up a universe of possibilities – a world of effortless data binding built right into the atoms themselves.

Connecting the Dots: Circuits of Data Flow

Imagine virtual electrons seamlessly weaving data connections between Atoms. Just like their real-world counterparts, these connections come in different flavors:

  • Conductors: Allow data to flow freely in both directions, enabling two-way data binding.
  • Diodes: Act as one-way valves, directing data flow like a digital traffic light, perfect for one-way data binding.
  • Capacitors: Don't directly transmit data, but instead accumulate changes in potential like miniature data batteries. When triggered, they send notifications to bound Atoms, enabling reactive data binding without actual data exchange.

Think of a Capacitor as a watchful gatekeeper, alerting an Atom when its bound partner experiences a "voltage spike" in its value. This allows the Atom to react without directly receiving the new value, opening up possibilities for sophisticated conditional responses.

The Power of Simplicity

This "atomic" approach to data binding offers several advantages:

  • Ease of Use: Bind data with just a few lines of code, eliminating complex binding frameworks.
  • Flexibility: Choose the right "circuit" for your needs, be it unidirectional, bidirectional, or reactive.
  • Efficiency: Leverage built-in mechanisms for minimal overhead and optimal performance.

Virtual Physics Data Binding empowers you to build dynamic, responsive applications with intuitive ease. Unleash the power of the atom and watch your data dance!

Conductors in Action: A Code Example

To illustrate this atomic ballet in action, let's examine a code snippet that demonstrates two-way data binding using conductors:

val atom1: Atom = Atom().with("ATOM1")

val atom2: Atom = Atom().with("ATOM2")

val atom3: Atom = Atom().with("ATOM3")

// Connect atom1 to atom2 and atom3, forming a synchronized circuit

atom1.conductor_(atom2).conductor(atom3)

// if any atomic value changes they all will change

and here is a code snippet to demonstrate diodes (one-way data-binding)

atom1.diode_(atom2).diode(atom3)

// if atom2 changes, so will atom1 which is downstream from atom2 while atom3 will remain unchanged (upstream)

// however if atom3 changes, all three will change in order

// furthermore, we can create circular dependencies:

atom1.diode_(atom2).diode_(atom3).diode_(atom1)

// if any value changes all values will change in order and this will not create an infinite loop //

Note:

An underscore after the diode_ , atom1.diode_(atom2) means the atom on the right will be returned as the target for the next diode.

An underscore before the _diode, atom1._diode(atom2) means the atom (atom1) on the left will be returned as the target for the next diode.

Effectively, the _ points to the argument that will be returned next. This allows diodes to be chained in sequence, or for tree shaped arrangements

atom1._diode(atom2).diode(atom3) // atom2 and atom3 BOTH connect to Atom1

Beta Decay in Virtual Physics: Unlocking Data Rollback using Isotopes

Virtual Physics draws inspiration from nuclear physics to introduce a powerful concept called beta decay. This mechanism enables flexible data manipulation and rollback capabilities within Atoms and Molecules. All Atoms and Molecules at any time can be converted into new isotopes that store their previous values in Neutrons. Yes it makes the atom heavier as in the real world, but it also gives all atoms the capability to do built in rollbacks at any time.

Key Concepts:

  • Beta Decay: Mimics the natural process of converting protons into neutrons, creating new isotopes. Serves as a mechanism for storing previous values and enabling rollbacks.
  • Isotopes: Chemically equivalent Atoms with different numbers of neutrons, representing different states of data.

Sample Code

val atom = Atom().with("InitialValue")

atom.betaPlusDecay("new value") // Atom now has a new value

atom.betaMinusDecay() // Atom rolled back to its original value "InitialValue"

This functionality is built in to all Atoms, Compounds, and Molecules

Building Blocks of Insight: Data's Chemical Revolution

Rows morph into molecules, data fields become atoms and queries become catalytic filters, extracting insights with the precision of a chemist.

Beyond Static Structures: Built-in properties become defining elements, relationships blossom, and generic functions operate with ease. Data evolves into a dynamic landscape of interconnected molecules.

Unleash the Potential:

  • Adaptive Structures: Build data structures that can bend and shift like nature's creations.

  • Intuitive Tools: Craft easy-to-use tools for exploration and analysis, mirroring the simplicity of chemical reactions.

  • Hidden Patterns: Uncover hidden connections and forge powerful insights, fueled by the magic of catalytic queries.

  • Elegant Efficiency: Create a new generation of data systems that reflect nature's efficiency and grace.

  • Code Example:

Kotlin

class VTestChemistry {
    private val polymer = Polymer()

init { // Add rows to polymers (natures repeating molecular structure)
    polymer.bind(AddressRow().with("name1", "address1", "city1", "state1"))
    polymer.bind(AddressRow().with("name2", "address1", "city1", "state1"))
    polymer.bind(AddressRow().with("name2", "address1", "city2", "state1"))
}

fun test(): Polymer {
    val filter = Filter().with(polymer)  // Create a Filter Catalyst
        .where(Name().with("name2"))
        .where(City().with("city2"))

    return filter.activate() as Polymer  // Execute the catalyst
}

}

// This sample builds a Polymer chain using AddressRow "molecules".

// Filter acts as a "catalytic function", extracting specific data.

// All other applied data-binding circuits and rollback capability still exist in the result set.

Elements Are Here !!

Elements: Elements are Self-Describing Building Blocks for Virtual Physics. Elements serve as runtime interfaces in Virtual Physics, ensuring each element has the correct number of protons (e.g., Hydrogen: 1, Helium: 2, Lithium: 3).

Key Attributes

  • Value: This core property represents the element's fundamental data relevant to your application e.g., ZipCode), and is the smallest Atom you can use (Hydrogen).
  • FieldName: Specifies the name associated with the Value for clarity and organization.
  • Access Level: Controls access and modification permissions for the Value within your application.
  • Alias Name: Provides an alternative name for the FieldName, promoting readability and flexibility.
  • Custom Protons: Beyond the minimum atomic number, additional protons can store application-specific metadata, making each element truly self-describing, and you can use and mix any combination of protons to create any element you need. -- The periodic Table gives us over a hundred elements we can choose from!

Unique Advantages

  • Self-Describing: Elements carry all necessary information, eliminating the need for external parsing tools (like for JSON or XML) to carry the meta-data.
  • Transmissible and Absorbable: Atoms can be emitted and absorbed, facilitating data exchange and communication between different parts of your application.
  • Seamless Integration: Works directly within your Virtual Physics environment, offering a natural and efficient way to represent and manipulate physical entities.

-------USING GRAVITY-------

To better understand the concept of gravity in the context of object-oriented programming, consider the following analogy using celestial bodies: Imagine you have four objects representing the Sun, Mars, Phobos, and Deimos.

The goal is to share information between these objects without polluting them with unnecessary data. In this case, the city field of the Sun is needed by the two moons (Phobos and Deimos) but not by Mars.

Without using a gravitational field concept, you would need to modify Mars to accept the city field and pass it through to its moons.

By using gravity as a metaphor for variable sharing, each moon can directly access the city field, pulling it into its scope when needed. This simplifies programming by reducing unnecessary modifications and data transfers between objects.

Any object that extends Particle can feel the effects of Gravity

  • ** Examples and sample code are coming soon **

Get Started:

  • Download the library:

    The quickest way to use it is to clone it, then open the VirtualPhysics directory using IntelliJ.
    Intellij has full support for Kotlin. There is nothing to "install" since VirtualPhysics has no dependencies beyond Kotlin itself and the JVM.

  • Review Documentation and UML diagrams: The UML diagrams will help you gain a comprehensive understanding of the intricate relationship between programming and physics. Many class files include Wikipedia links, allowing you to explore particle details and observe how their patterns are interpreted and implemented in the programs.

  • Dive into our detailed documentation: coming soon.

  • Join the discussion on our forum: Available Now.

  • Watch our video tutorials:
    Intro to Virtual Physics: https://www.youtube.com/watch?v=0u_rUdT7cTg&t=99s

Virtual Physics. Unleash the engineer within.

There are many more super-powers coming to VirtualPhysics --so stay tuned!

Note:

Virtual Physics is Ideally used when writing Kotlin on both server and client side

If you are using Kotlin with React or Jetpack Compose this can save you a lot of time by elminating the 
need for JSON messaging or using Protoncol buffers to send data and/or metadata
Simply .emit() and absorb and share the same object on both sides.

Releases

No releases published

Packages

No packages published

Languages