Horns of the dilemma - C++ & Python binding or Julia

Aah… I am at the crossroads - tried-and-true marriage (C++/Python) or solo act (Julia). I am starting new in julia and i must be honest - it looks great for an engineer interested in scientific software.
i hope i will be a net positive in the group.


As with any object oriented language (like C++/Java/Pyton) i usually start with Design Pattern to understand the big picture and rise above syntax.
The same thing I have started with Julia, trying to implement a few GoF design pattern in julia. I know that may not be a good start wrt to julia - as it’s not a OO language - but anyway, it helps me to understand the architecture. So… here we go… my first encounter with Julia - a strategy pattern.

abstract type JourneyToTheAirport end

struct Bus <: JourneyToTheAirport end
struct Metro <: JourneyToTheAirport end
struct Auto <: JourneyToTheAirport end

gotoairport(::Bus)   = println("🚌 Journey by bus... hope there's no traffic!")
gotoairport(::Metro) = println("🚇 Journey by metro... fast and efficient.")
gotoairport(::Auto)  = println("🛺 Journey by auto... hold on tight!")

# 1. Create a mapping of strings to Type Constructors
choices = Dict(
    "bus"   => Bus(),
    "metro" => Metro(),
    "auto"  => Auto()
)

function run_app()
    println("How do you want to get to the airport? (bus, metro, auto):")
    
    # 2. Get user input and clean it up (lowercase and strip whitespace)
    user_input = lowercase(strip(readline()))

    # 3. Look up the strategy in our dictionary
    if haskey(choices, user_input)
        strategy = choices[user_input]
        gotoairport(strategy)
    else
        println("❌ Sorry, '$user_input' is not a valid transport option.")
    end
end

run_app()

Enjoy

2 Likes