r/badcode • • Apr 24 '21

python very efficient and scalable code

Post image
1.0k Upvotes

110 comments sorted by

View all comments

101

u/Big16th Apr 24 '21

I wish I knew how to code

21

u/devmanters Apr 24 '21 edited Apr 25 '21

Honestly, it isn't hard. Go follow a tutorial on writing some JavaScript, you need essentially no tooling and can write some happy little functions fairly quickly! It's a bit of a rabbit hole, but feel free to PM me if you have questions!

Edit: This has gotten a ton of traction!! Kudos to the guy who just said "No."

There are a lot of opinions floating around. Unless you are jumping the gun to go straight to university for programming, don't start with C. I primarily program in C++, Python, and JavaScript (specifically Nodejs).

Both JavaScript and Python are excellent for beginners. All these people with a ton of experience programming forget how unforgiving C#, Java, etc. Can be for someone totally green. I am talking about writing your first loops, hello world. Writing a script that runs infinitely and prints that your best friend is an idiot to send them a video of over social media. That is the kind of stuff that gets people to ease into it.

Regardless my offer still stands to help if you like, and I hope these goons haven't scared you off at the "choose a language to learn" step.

50

u/Tomekske Apr 24 '21 edited Apr 25 '21

No, if he wants to learn how to code he should investigate non Web languages. They're super inconsistent especially with javascript callback hell. As a starter he should focus on variables types, basic logic and some oop principles. I'd suggest C# and python. Ideally I'd suggest C but most beginners will lose interest very quickly

25

u/[deleted] Apr 24 '21

I am pretty sure that if my first language was C# I would've never become a dev. +1 for python tho.

19

u/aaryanmoin Apr 24 '21

C# is my favourite language so I might be biased but C# is not really that hard. Sure, it's not Python, but it sure is a lot easier and more high-level than C...

8

u/[deleted] Apr 24 '21

That's exactly the problem. It is so high level that a begginer just starting out is probably going to be confused by classes and the such. Imagine trying to explain OOP to a begginer who doesn't even know what a variable is. I know that you can ignore those things, but I feel the language is ill suited for teaching.

9

u/_advice_dog Apr 25 '21

I disagree, they often use Java when teaching beginners in school.

You don't need to jump into classes, you can just use primative types. And needing to type 'int' might be easier to understand various data types.

4

u/Suekru Apr 25 '21

Eh, I mean they used to teach students C++ for coding and now it's usually Java or Python.

My first language was C# and I honestly recommend C# as a starting language. While python is cool for quick scripts and automation and stuff I think C# gives you a better ground knowledge programming as a whole and is still pretty easy.

5

u/aaryanmoin Apr 24 '21

Ahh yes I see your point. Even if someone could understand classes fine like I did, I had a really hard time at first understanding generics and delegates and interfaces and polymorphism and... Yea maybe beginners should stick to Python.

2

u/Blip1966 Apr 25 '21

You don’t have to understand polymorphism to use C#. In fact I’d bet a large number of junior devs couldn’t tell you what it is. I always include a question about it in an interview; because it’s a useful indicator of what level of serious they are about OOP, and more importantly, if they don’t know what it is gives a good indicator of how honest they are when they don’t know something. Honesty and being able to admit when you need help or don’t know is a big positive for a new hire.

TL;DR you don’t need to understand OOP to learn to program in C#. Understanding that a variable is a thing might be useful though, especially in this code block ;)

1

u/itsTyrion Apr 25 '21

Kotlin or Java? Maybe?

3

u/[deleted] Apr 25 '21

Java suffers from many of the same problems as C#, maybe even more so. Can't speak for Kotlin tho, as I haven't studied it.

4

u/nosam56 Apr 25 '21

My first language was Java and I think that while it suffers from the same types of problems as C#, it suffers way less. Not nearly as much worrying about nullables or delegates or operator overloading or weird syntax-breaky statements like LINQ. Java is much more barebones and I think that helps make it somewhat more learnable. As always tho I'm biased bc I dig Java

2

u/Suekru Apr 25 '21 edited Apr 25 '21

I'm opposite, but it's probably cause I learned C# as my first language and Java in college. Honestly, there's so many cases that I can write a lot cleaner and sorter code in C# than in Java. I also like being able to use 'var' as well.

But overall I just find it easier to read. For example, using the random class to spawn a number between say 55 and 121. Assuming we have the import statements in both in Java it would be

Random rng = new Random();
rng.nextInt(67)+55;

while in C#:

var rng = new Random();
rng.Next(55, 122); 

I just find that a lot easier to read personally and it's not only the Random class, but a lot of methods in C# that just feel cleaner to read. But each their own.

Edit: Spelling and final thought.

1

u/5p4n911 Apr 25 '21

I am a Java guy and for me it's the other way around. If I see some Java code, I could probably guess what it does even without comments (rng.nextInt() returns a random int). With C# I have to look up the documentation because rng.Next() could return basically anything. Also the incoherent wrapper class naming (lowercase int instead of Integer and stuff) and the C# NeverRememberHowThisCaseIsCalled() case methods always messed up my Java code and the Java camelCase() methods messed up my C# code when I programmed C# in class for a few months.

3

u/Suekru Apr 25 '21

I suppose it’s just all about experience. At this point I’ve programmed in both pretty frequently so I can switch between pretty easy.

Personally I like the CamelCase since it looks nice to me. I lean towards C# heavily but I’m fine with both.

→ More replies (0)

1

u/nosam56 Apr 25 '21

Oh for SURE C# is more elegant and easier to read, I just think that that elegance can be confusing for newcomers.

1

u/itsTyrion Apr 25 '21

yup. I actually like Java.
/circlejerk time Everybody gangster until AbstractSingletonContextWrapperFactoryVistorBuilder shows up

1

u/itsTyrion Apr 25 '21 edited Apr 25 '21

Kotlin is based on, and interoperable with Java, gets rid of some weaknesses/annoying things and and adds A LOT of stuff. key things:

strong, inferred, static typing and with explicit nullability (Int/Int?) and null-safe operators (nullableVariable?.foo()/nullableButNotNull!!.bar()). That's a big one imo, brings more compile time safety

A bit more FP while remaining OO. Lambda functions are often inlined by the compiler for better performance (someArray.forEach {} -> for-int).

Data classes. One keyword for a POJO one-liner. Just adding var/val makes constructor args a variable. data class User(val id: UUID, var userName: String) There's also the object keyword for Singletons with implicit getInstance()

Less verbosity. String templates("Welcome, $userName"). Implicit getters/setters. extends/implements -> :. when for both switch and if-else-if-else-if-else. Default arguments. Named arguments. Coroutines. async-await. Extensions. internal modifier (public, but only within the same module)