Julian python

I’ve been learning Julia since the 1.0 release, but had to slow down because my job is python-centric and I need to improve my python skills quickly to keep up.

For the 2 projects I’m assigned the team is using python and I must follow. Starting in February next year I will start a fresh project and should be able to pick Julia.

Question: what can I do in python that would make transitioning to Julia later easier?
What habits should I have? What commands should I use and what should I avoid? That kind of thing.

In summary, what’s the ‘‘Julia-way to write Python’’?

1 Like

It sounds like you want to cheat on Python :wink: Cheating never works in the long term… :see_no_evil:

As a Python power-user, I can only recommend some general things like: write clean code, document your stuff, do unit tests and integration tests, continuous integration and all of them as automatised as possible. These are things which are (should be) common regardless of the language you work in, so it’s good to practice them whatever language you code in.

In my opinion it makes no sense to try to do Julian-like stuff in Python as both languages have completely different designs and semantics. You should focus on Python and the corresponding project goals. I am sure you will learn new problem solving strategies when you discover new languages but I don’t think it’s a good idea to enforce it.

Also I am not sure what you mean with

“What command should I use and what should I avoid?”

You should avoid writing bad code :slight_smile: If the project constraint is “Python”, then it should be a Python software. Someone else will probably take over in future and the job description will include “Python developer”, so people will expect something which is Pythonic and not Julian.

I can understand that you are eager to use Julia, but I don’t think that’s the right approach.

7 Likes

One piece of advice I’ve seen given in Python circles is “don’t overuse classes”. This would be relevant in Julia since there are no classes so learning to “think outside the class” is helpful.

https://pyvideo.org/pycon-us-2012/stop-writing-classes.html
http://ginstrom.com/scribbles/2008/10/06/dont-overuse-classes-in-python/

But in general I think it’s best to “get in the mood” of a language that you’re using. I had to program in PHP a bit back in 2009-2011 and it was jarring at first but after a while you learn to lean heavily on PHP’s “all things to all people” array type and then things start to feel more natural and fun. Try to get the feel of a language and it will help you appreciate both it and how other languages are different.

8 Likes

As already mentioned, I think it’s important to focus on idiomatic style of the programming language you are using. Having said that, I think there are things in Python that are conceptually closer to Julia.

For example, you can use type annotations in Python. You can get used to concepts like type parameters with it (although you need to re-learn syntax and subtle differences to Julia afterwards). If you type check with mypy it forces you to write “type stable” code (in Julian terminology). It is (used to be?) important for writing Julia code with good performance.

There is also functools.singledispatch that lets you write normal/free/non-method functions that can be dispatched on the type of the first argument. I guess you can write more Julia-like but yet Pythonic code (it’s in the stdlib after all). But I’ve never used it seriously so I’m not totally sure about it.

I’d emphasise the “overuse” part; it’s good to write classes in Python if you need to (well, of course). But, if you do, write single-purpose small classes that compose well with others, rather than a single big class that does everything. This practice would translate well to Julia (to any language, I guess).

Python 3.7 has dataclasses in stdlib which is kind of like Parameters.jl/QuickTypes.jl in Julia (see also attrs). It helps you write small well-behaving classes because it auto-generates all tedious code for you.

Julia programs are often organized using interfaces. In Python, you can use abc to make the interfaces explicit.

If you have a lot of I/O in your project, using async/await (e.g., via asyncio) also may help you get used to concurrent programming in Julia.

On the side of tooling, pipenv is closest to Pkg.jl. Its Pipfile and Pipfile.lock are like Project.toml and Manifest.toml of Pkg.jl.

Finally, let me emphasise again that all the connections I make are not exact equivalences. There are differences you need to learn when start using Julia.

1 Like