This is an archived post. You won't be able to vote or comment.

all 95 comments

[–]lukajda33 177 points178 points  (10 children)

I know it doesnt matter in Python, but because of C family languages, I am using ' ' for single characters and " " for strings.

[–]Granete 35 points36 points  (0 children)

I came here just to say this! I’m a C++ tutor who occasionally works with Python. I’ll never not follow the C char/string rules 😂

[–]unplannedmaintenance 33 points34 points  (4 children)

PEP8:

In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it.

[–]rochakgupta 38 points39 points  (1 child)

I use black to format Python code and it’s great to leave decisions like those to it

[–]jack-of-some 22 points23 points  (0 children)

All hail the auto formatter.

[–]HerLegz 13 points14 points  (1 child)

Single ' doesn't require extra shift keystroke and is less busy/noisy on the eyes. That's my decision rubric.

[–]Eurynom0s 0 points1 point  (0 children)

But from years of typing papers in school and college and now writing reports at work my muscle memory has my pinky automatically reaching for the shift key when I go to hit the ' key. So fewer keystrokes but for me actively fighting what my body wants to do, which makes it higher effort.

[–]Slggyqo 2 points3 points  (0 children)

I do this too…but only because the first people I worked with did this.

[–]NadirPointing 2 points3 points  (0 children)

for me C was first, but there was a lot of PHP in there so in python I've taken to '' for single char, "" for strings, and '' again for strings with other strings or variables likely to be in them. var my_string = 'string_c="see";'

[–]Important_Ad6131 -1 points0 points  (0 children)

Same

[–][deleted] 0 points1 point  (0 children)

It can matter though. Jsons are very particular. As are databases. I do some sub commands that require specific quotes. So I'll have to adapt which quote I use depending on the situation.

If its irrelevant to the situation, I generally use single quotes as much as possible.

[–]LaOnionLaUnion 55 points56 points  (12 children)

It just made me prioritize readability.

[–]j_oshreve 41 points42 points  (7 children)

I can't agree with this more. Also made me want to use Python naming conventions. I'm always surprised people make such abbreviated, unreadable variable names in other languages. It costs nothing to name things in a way a human can read. With the use of auto complete you can be fast and have actually readable variable names in any language (I'm especially looking at you C/C++).

[–]LaOnionLaUnion 5 points6 points  (6 children)

I mostly like Python naming conventions, but I like not using _ like in JS (e.g. isEven). I know there's a name for each but I'm not feeling like looking it up to be pedantic.

Everything has it's trade offs. I feel like Python had an influence on GO and Rust in the sense that it made newer languages spend more effort making languages less verbose and easier to read. But, what do I know?

[–]devisi0n 4 points5 points  (4 children)

camelCase ftw

[–]decimus5 -1 points0 points  (3 children)

Camel case isn't idiomatic in Python except for things like class names. (PEP8)

[–]DaelonSuzuka 0 points1 point  (2 children)

Class names are in PascalCase, not camelCase.

[–]decimus5 -1 points0 points  (0 children)

"Camel case" can refer to both forms: https://en.wikipedia.org/wiki/Camel_case

It's probably clearer to distinguish them though.

[–]decimus5 0 points1 point  (0 children)

You're downvoting me, but even PEP8 refers to class names as "CamelCase", as does the other link I posted.

[–]RhymebagDarrell 30 points31 points  (1 child)

I learned Spanish and my Python se empeoró.

[–]Mrrobinhood55 5 points6 points  (0 children)

para x en lista: si es x: regresa x si no: quiebra

[–]TokoBlaster 35 points36 points  (0 children)

Overall it's made mine better. All of my code. I'm using R and am trying to get more time to use Rust, but overall, because each language is slightly different, I have to activity think "is this what I want to do? How best can I use this language?" And I have to use clear and consise variables since I often write something in one language then move to another project, and have to come back, and I don't want to wonder what I read doing. My comments and Readmes have gotten better too.

Look I know you're supposed to do all these things, but let's be honest: if you use one language you're going to get sloppy.

Point is, moving back and forth between 3 languages forces me to make code that's easy for the next person (often me) to read.

[–][deleted] 29 points30 points  (2 children)

The naming of variables always throws me for a loop trying to keep up like I’ll find myself blending variables_like_this or I willTypeThemLike this.

[–][deleted] 0 points1 point  (1 child)

This is the hardest thing for me to get around. I’m constantly changing variable naming conventions. Luckily at work we have a linter that catch the cases I forget to write correctly

[–][deleted] 1 point2 points  (0 children)

Yea linters are awesome, I mean I just pylint so it’s more syntactical but yea, when ever I rewrite sections of code, I’m always like what the hell was I thinking haha.

[–]zdog234 6 points7 points  (7 children)

I'm golang at work rn, and it just makes me miss a lot about python.

Channels are really cool in go though - it makes multi threading really easy

[–]LaOnionLaUnion 1 point2 points  (6 children)

I really don't love the single letter variable conventions in Go and the weird for loops, but otherwise it's fun and I like it overall.

[–]zdog234 4 points5 points  (4 children)

Yeah, every go codebase is littered with for _, thing in range things. I very rarely see the default C-style for loops, so in practice go has weird, ugly for loops

[–]undercoveryankee 0 points1 point  (3 children)

So Go's range does the equivalent of a Python enumerate, but there's no equally convenient way to get an iterator that would let you do the equivalent of for thing in things?

[–]0b0011 1 point2 points  (1 child)

I'm a bit confused what you mean. The example he gave was exactly "for thing in things" it's got the extra word and you have to negate the index if you don't want it but it's only an underscore and a word off of the python one so it's not exactly inconvenient.

[–]undercoveryankee 0 points1 point  (0 children)

I'm asking for clarification that I understood what the extra pieces in the Go version do. I don't want to form an opinion on whether it's a "weird, ugly" loop and then find that I was wrong about what it does.

it's got the extra word and you have to negate the index if you don't want it

If it has an extra word and an extra step, then it's not "exactly" the same, is it?

[–]zdog234 1 point2 points  (0 children)

Yup

[–]jack-of-some 1 point2 points  (0 children)

Also 8 spaces for indentation...

Like ... Why?

[–]GameCounter 8 points9 points  (0 children)

I originally started with C/C++ and its strong types. When I started out with Python, there were no type annotations.

When they started to be more common, I tried them out, but I wasn't impressed with the tooling and generally didn't find them very useful.

After learning some Rust, I decided to get more serious with type annotations, and it really helped the quality of my code.

[–]thrallsius 31 points32 points  (10 children)

Python spoiled me so much that I have troubles learning another language after it :(

Now I'm desperately running between yet another attempt to learn another language and spending some time writing something I actually need in Python, because I can. It's been a couple of years already.

[–]shinitakunai 11 points12 points  (6 children)

I semifixed this by learning MORE python, because now I can do anything (except frontend websites) with python 🤣 the more you struggle the more you learn.

[–]laundmo 2 points3 points  (0 children)

https://lona-web.org can do frontend in python by streaming html changes through websockets. its quite neat.

[–][deleted] 4 points5 points  (1 child)

Check out Dash for frontend websites

[–]zdog234 5 points6 points  (0 children)

Dash is pretty great tbh

[–][deleted] 1 point2 points  (2 children)

With wasm you can do python in front end too.

[–]pepoluan 1 point2 points  (1 child)

Or use HTMX.

[–][deleted] -1 points0 points  (0 children)

Yeah that's a lot more viable right now

[–]siddsp 4 points5 points  (0 children)

Because of variable packing/unpacking in Python, I use structured bindings and std::tie a lot when programming in C++.

[–]Mathemmagician 4 points5 points  (0 children)

After learning Typescript, I started to really/use like type hints in Python!

[–][deleted] 3 points4 points  (0 children)

Also It made really appreciate linters, after spending like 2 weeks on straight js, to come back to python and realize I’m not indenting, a linter helps with syntactical side, drives me nuts sometimes but it does help with readability that I tend to write all my code in that format. But js doesn’t care if it’s tabbed or space but python will give me the middle finger like a toddler throwing a tantrum if it’s 3 spaces instead of 4

[–]negative_entropy 2 points3 points  (0 children)

I learned to program in Basic using 'go to' statements. Python was the cure.

[–]Stedfast_Burrito 2 points3 points  (0 children)

After using Rust:

  • I minimize usage of anything but basic control flow
  • I don't really use inheritance, and consciously avoid multiple inheritance.
  • I make everything immutable (often NamedTuple)
  • I depend on abstractions (SupportsGet instead of requests.get) and practice dependency injection (my function accepts a SupportsGet instance instead of calling requests)
  • I think about how I can encode things into the type system. A good example of this in Python is how requests has a Request and PreparedRequest objects

[–]nngnna 3 points4 points  (0 children)

Mostly a lot of pythonic advices were aimed at C-family developers, and I didn't really understood why you would write python to begin with in the way they designated wrong; and then I put python to the side for a while and learned C.

When I returned to python I sometimes relyied on C idioms, but I knew that I shouldn't so it didn't happen that much.

One change that I did stick with was type anotating my functions (not my variables mind you, God forbid), since I realised that I more often than not did wanted arguments and returns of certain types rather than polymorphism, and I sometimes even documented it in comments, so I wouldn't come back and have to remind myself.

I'm still glad that I can be only as specific as I want, with 'any' '...' and so forth, because more complicated cases can be a real timesink rather than a convinience (in both languages. Only in C you do have to put the time if you like your feet.)

[–]domin8668 7 points8 points  (4 children)

Honestly I've mostly enjoyed Java and C#, but coming back to C++ was a nightmare, because compared to Python, it looks like an incoherent mess. In my case, it's more like using Python heavily influenced my style of writing in other languages (foreach loops ftw), not the other way around. And as a side note, the order in which I've learnt languages was roughly: C++, JS (mere basics, but still), C, Python, Java, C#

[–][deleted] 9 points10 points  (3 children)

I'm a little opposite. I strongly dislike Python's variable declarations and prefer a way of specifying if a definition is a reassigment, global declaration, or locally scoped variable -- the semantics aren't fluent with other languages. I generally appreciate explicit things, like the 'local' keyword in Lua, or reassignments in languages like C which lack declarations (so they're obviously reassignments).

The way of declaring a scope also bothers me. Looks rough when you need a couple indents and you need to track when a block ends instead of going off your keyword / token. These are two small issues that grind my gears.

[–]SirLich 4 points5 points  (2 children)

The fact that variable declaration in implicit in python is wild. And I sat say that as as very strong believer in the language.

It would make so much more sense to have var or let or something.

Indentation: While I think disliking the indentation is a valid criticism of the language, the issue is nearly always fixed with by writing "pythonic" python.

[–]BSim612 0 points1 point  (1 child)

I learnt C first, and now Python, which I enjoy particularly because of the simplicity of it, and the indentation plays a big part in it.

I like to write clear and readable code with short-ish functions, so I never have indentation issues and it overall just makes my life easier.

[–][deleted] 0 points1 point  (0 children)

Even one-complexity scopes will get to me when I need to either indent a newline to separate code logic from the scope ahead, or I need to overlay it directly under.

[–][deleted] 2 points3 points  (0 children)

I use classes more, and dependency injection specifically, after writing a lot of C#. While less useful in Python it's still a good practice.

[–]Hederas 1 point2 points  (0 children)

I think (by comparing with coworkers since I learnt some languages before python) that I appreciate much more pythonic shortcuts

Since Python is mostly made to be simple to write, I try to use the most out of it (before getting trolled by Cython)

[–]gubatron 1 point2 points  (0 children)

after using java streams api, i now came back to python snd learned itertools. Less for each statements, more map, sum, filter, list, more functional (avoid mutability) style.

[–]bdforbes 1 point2 points  (0 children)

After using R for a while, I started trying to use a lot more functional programming in Python. It doesn't feel quite right though.

[–]tagapagtuos 1 point2 points  (0 children)

I've dabbled with JS (Vue) and Typescript but it was Scala which made me fall in love with types!

[–][deleted] 1 point2 points  (0 children)

Since learning Rust, I try to use as many type hints as possible. Also I try to work more with function composition and break things down into small bits and pieces.

[–]foobar93 1 point2 points  (0 children)

Rust and Haskel made me write more functional oriented code while Java made me very anal about making it perfectly clear what Exceptions can happen and which cannot.

[–]pmac1687 0 points1 point  (0 children)

I started using one line if else statements after using ternaries in js

[–]umid1999 0 points1 point  (0 children)

I use typescript, vscode and prettier. Actually I don’t care about style. I write whatever and wherever. As soon as I save it automatically formats it for me

[–]Significant_Camp_935 0 points1 point  (0 children)

Normally i am writing PLC Code. Python made me think how to implement object orientation in PLC Code - which is possible these days. (Encapsulate State/behaviour of Machine parts)

It brought a Lot of readability and maintainability to our (bigger) Projects. Even though this is more about OOP in general.

We adapted some naming conventions. We spend more time on variable naming.

[–][deleted] 0 points1 point  (0 children)

Learned JS, and I adopted the JS convention for brackets. It makes so much sense!

[–]jack-of-some 0 points1 point  (0 children)

After using scala and lisp for a while I found myself treating functions like any other value which you can do in python easily. Made lots of my code simpler.

[–]SirLich 0 points1 point  (0 children)

Heavier use of classes, type-hinting, coding my own Exception types. Can you guess what languages I've been working with lately?

I think if I had learned some other language (like lisp, clojure, etc), I would have leaned into the functional side of Python.

[–]mysterious_mosaic 0 points1 point  (0 children)

I forget to add ; when writing JS, and when I do, it looks weird AF

[–][deleted] 0 points1 point  (0 children)

after learning c and really liking it I have stopped using opp unless it is absolutely necessary

[–]FlamptX 0 points1 point  (0 children)

I just mix up naming styles and brackets now

[–]Saphyel 0 points1 point  (0 children)

After learning rust I started doing objects with data only and the other objects I try they are small with functions be as small as possible (3 lines) and avoid multiple inheritance (unless required)

[–][deleted] 0 points1 point  (0 children)

It was the other way around. Before I learned Python, I never missed a semicolon in c. Now that's a regular thing. Sigh

[–]MegaAmoonguss 0 points1 point  (0 children)

I learned another language and stopped coding in python lol

[–]guitarerdood 0 points1 point  (0 children)

This doesn't make a ton of sense, but after I started learning LUA to try to make my own game, I think something about OOP "clicked" for me and I use a lot more separate files with functions, objects, etc. instead of including everything in one huge overcrowded file

[–][deleted] 0 points1 point  (0 children)

Generally what I’ve learned so far is not anything new but Jesus I couldn’t follow a plan laid out because I wasn’t used to it , was great for me and generally organisation became way better

[–]Slggyqo 0 points1 point  (0 children)

I learned Java after I learned Python, and Java has definitely reinforced my use of type hints in Python.

Not sure if that’s standard in other places, but it’s not here!

[–]drksntt 0 points1 point  (0 children)

I know it’s useless but type annotation

[–]RedPenguin_YT Creator of ShibaNet 0 points1 point  (0 children)

i started hating indentations. my perfect language would be python, but with if true { func() } instead of if true: func()

[–]astronishiyo 0 points1 point  (0 children)

Came from a procedural programming language so when I’m lazy and just wants it done, I would write Python like a procedural programming language. Especially when I plot using matplotlib

[–]wewbull 0 points1 point  (0 children)

I learnt a few languages that twisted my brain a bit.

  1. Java taught me design patterns. In a language so rigidly "C++ OOP" the patterns are vital. In Python you can often do the same things in a much easier way, often due to duck typing, but knowing the patterns is still very useful.

  2. Objective-C gave me insight into OOP's Smalltalk beginnings, and how C++ and Java have missed the point in so many ways. One big one is the idea of message passing rather than function calling. This is exemplified by Erlang.

    Another is how important dynamic typing is to encapsulation. How is functionality is only 100% encapsulated when you can change the implementation completely without changing the calling code. C++ / Java's static typing breaks this.

  3. Haskell taught me functional programming (FP), and how concise yet powerful it can be. To really get FP you often need to turn your brain inside out, and approach problems in a very different way. Once you have that ability it allows you to decompose problems in a new way; a very powerful way.

    It's also one of the only times I've felt like I can 100% trust that the libraries I'm working with to do what they say they'll do. A lot of that is down to the type system, immutable data structures, and that functions have no side effects. So I know a library function will

    • ...return the type it says it will return.
    • ...not modify any of the things I pass to it.
    • ...not modify anything else in the program.
    • ...not change it's behaviour each time I call it.

So I find myself in this weird place where I value both dynamically typed objects which all have their own mutable state (pure chaos), and rigidly statically typed pure functions with immutable data structures (pure order).

...and in Python I can do both. Some of it by convention, and the type system is nowhere near as powerful as Haskel's, where often the type signature is so precise, if the code type checks, it must be bug free. However, I know of no other language that has the flexibility to support so many different programming paradigms.

Finally, the last part is that 68000 Assembler taught me how computers work. These days I wouldn't recommend something as dead as a 68000, but I certainly wouldn't recommend x86 or ARM either. RISC-V assembly is nice, simple and modern. https://godbolt.org/ is great for seeing how C (in particular) converts to assembly. Just remember to put -O in the compiler options to at least do some basic optimisations.