1

Hi all.
As some of you maybe know, I have tried to learn programming for more than 10 years, but always given up for a lot of reasons. I was really excited then BGT came, and I really did my best to read the manual, understand it all and give it a serious try. I don't know why, but I simply don't get the basics at all. The manual is very well written, some of the best I ever have seen, but there is something, maybe regarding to how the manual explains BGT or something about the language which I don't get. I have tried like 4 times, find it overwhelming and given up because of this.
I have heard so many times that Python is a great programming language for a lot of things. I gave it a try some years ago, but at this time I was afraid to use the terminal on my Mac, so I didn't got very far.
Then, suddenly, out of nowhere, when I'm very busy with other things and there are a ton of other more important things which I really should take care of, I got motivated to give Python a serious try once again. I come from knowing close to nothing about programming accept for a bit of Auto it and html, so I need to learn it from the very beginning.
This is my background. now you might ask, what will I use it for? What kinds of programs do I have in mind?
well, I'm interested in making games if I ever get good enough. I also wanna make small programs which communicates with other programs to make inaccessible things more accessible. I wanna make plugins to programs which might make them more accessible. I wanna make small teaching programs to train blind people in math, typing skills and other kind of training programs. If I'm not able to make some of this, then I hope I at leased will learn more about how programming works in generel.
So, now my question: What are the pros and cons in Python? This question is both ment for beginners and for advanced programmers, who wanna develop something professionel and advanced.
I have looked at this tutorial:
https://learnpythonthehardway.org/book/
which is really good the way it is written, because it force you to write all the examples, it gives you hints to try something with your examples and tells you to figure out what it does and if you don't figure it out, it's not very important. It force you to learn by figuring some of the things out on your own in a really great way.
Comments, opinions and thoughts would be very much appreciated. If there has been a simuler discussion previously, then please post a link.

Best regards SLJ.
If you like the post, then please give it a thumps up.
Feel free to contact me privately if you have something in mind. If you do so, then please send me a mail instead of using the private message on the forum, since I don't check those very often.
Happy gaming... :D

Thumbs up

2

Pros: simple syntax, vast resources, dynamic typing, built-in help system, lots and lots of libraries.
Cons: Simple programs take up 10mb more filespace than they should in redistributable form, dynamic typing, I don't much like the way python handles global and member variables in functions/methods but that's just me, and... that's all I can think of ottomh.
Oh, and the dependency scavenger-hunts. Those things are vicious.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up +1

3 (edited by Hrvoje 2017-08-14 09:53:41)

Python is my favorite language, I love it and I'm using it around 5 years in addition to Java which I'm using at work and for developing Android apps. Python's Pros are definitely those mentioned in previous post, plus fast development because you don't have to wait the app to compile first before it can run, so the same advantage as with BGT. Python compiles into bytecode just instantly. Cons, at least for me, are those mentioned in previous post, plus that it's execution may run slower than C or C++. The reason why I'm unsure to write games in Python is because games written in Python at least from my experience run slower. Even BGT works faster than Python, because I'm feeling performance difference when playing e.g. Undead Assult which is written in Python and Manamon which is written in BGT. I was trying myself to code a sidescroller in Python, and as I added more moving objects on the field, the game ran slower and slower. I guess that multithreading may help in this, but on the other hand, having more than 30 objects in 30 different threads is also not a good idea, but correct me if I'm wrong.

Thumbs up +1

4

Thanks for your comments so far.
@Cae_jones: What's dependencee scavenger-hunts?
@Hrvoje Have you looked at Pygame or other game libraries?

Best regards SLJ.
If you like the post, then please give it a thumps up.
Feel free to contact me privately if you have something in mind. If you do so, then please send me a mail instead of using the private message on the forum, since I don't check those very often.
Happy gaming... :D

Thumbs up

5

Yes I looked at both Pygame and Pyglet. I chose Pyglet, though Pygame is more beginner-friendly.

Thumbs up

6

Dependency Scavenger Hunts are when you install a library, then you get an error because it depends on another library. Repeat ad nauseam.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

7

Ah, I got it. Sounds very confusing... smile
@Hrvoje: Have you asked on any Python forums regarding this issue when making games? I mean, a popular programming language shouldn't react like this. There must be a solution to this. A lot of games has been made in Python... I'm surprised if that's a limit of the programming language itself...

Best regards SLJ.
If you like the post, then please give it a thumps up.
Feel free to contact me privately if you have something in mind. If you do so, then please send me a mail instead of using the private message on the forum, since I don't check those very often.
Happy gaming... :D

Thumbs up

8

I think Python might not be the problem, because audiogames usually
require little processing power. Even if you need to do thousands of
calculations per frame, you can use C extensions that interface with
Python to do that for you.
To see what is causing the problem, you can use a profiling module (like
cProfile), which tells you the functions that are taking the most time in your game.

Thumbs up

9

@Hrvoje, BGT has a disadvantage compared to Python -- there's no such thing as 'fast development'. BGT compiles it's code to bytecode, not native CPU instructions (although you might think so). Python, on the other hand, is compiled to bytecode and allows for extremely fast programming, immediate software reloads, among other things. It does, of course, have a few disadvantages:\

  • You cannot manipulate low-level things like pointers, CPU registers, etc.

  • Python cannot be very easily translated into lower-level languages without programs like cython (which don't even translate your code into very readable C code in the first place).

  • The highest level of optimization you can do with Python is C extensions.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

10

Hi.
So, this question might be quite stupid, but here goes. smile
What is the point and the advantages of using low level languages? I mean, if you can code what you want and need in Python, what's then the point of making it in C++, for example? The only big advantage I can think of is, if you wanna code something for an other peace of hardware than a computer running an operating system.

Best regards SLJ.
If you like the post, then please give it a thumps up.
Feel free to contact me privately if you have something in mind. If you do so, then please send me a mail instead of using the private message on the forum, since I don't check those very often.
Happy gaming... :D

Thumbs up

11

Lower level generally means more options and control which allows you to be a lot more explicit and efficient with instructions, but at the cost of greater complexity, time to write, and readability. Pythons automatic memory management can make writing code easier and faster, but it can be problematic if your working with a system that has limited resources, have to perform a lot of highly complex operations, or interface with hardware like the aforementioned cpu registers for writing things like operating systems and such.

It really depends on what you plan on doing. Programmers generally learn several languages as they go, leveraging their advantages and disadvantages to accomplish whatever the task at hand may be. Python interfaces rather well with C, such as with ctypes for pointers and other libraries, so you'll likely pick up a bit of it eventually.

-BrushTone v1.2.8: Accessible Paint Tool

Thumbs up +1

12

The answer that inevitably comes up involves speed, as higher-level languages (or the popular ones, anyway) rarely use CPU instructions directly, and even when, everything has to pass through all the layers of obfuscation the language uses to make itself desirable in the first place. C and C++ are a step above assembly code (a big step, mind), and C compilers more or less translate C code into machine code. The limitations are established by the hardware and the Operating System, making it faster and more versatile than higher-level languages, but also much harder to manage and much more complicated.
Then, if you really need optimizing for speed or hardware, you can mess with assembly code. This varies from processor to processor and is mostly used for compilers, OS stuff, and embeded systems (think everything the Raspberry Pie is used for, before there was a Raspberry Pie).

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up +1

13

@SLJ,

Once you finish learning Python, the next step will be trying to develop a coding mindset.  For most, that involves writing and reading a lot of code.

Here is another way to look at it.  Most introductory books will teach you a language.  They would be similar to reading a book about Legos that tells you all about the various types of Lego bricks there are and teaches you a few ways to put them together. However, this doesn't make you a master builder. To become a master builder, you also need to develop a mindset where you are able to solve problems using Legos. The more time you spend building things with Legos and the more time you study how other people build things with Legos, the better you will become at that mindset where you can understand a problem and know how to combine all the bricks to solve the problem with Legos.

One book I have found useful is

Thumbs up +1

14

Yep. From my experience, learning the language is not a big deal. However, learning how to develope for certain platform or hardware is much harder and requires more time and experience to learn. For example, I've recently learned Java in order to prepare myself for Android development journy, and this was much quicker than learning how Android components and building blocks work. In fact, even after about 6 years of coding, I'm still not a quite good coder as I want to be.

Thumbs up

15

@Hrvoje, I'd go learn Scala and not bother with Java. You can just as easily develop android apps with Scala as you can with Java, although developing android apps with Scala instead of Java might actually be far easier. I'll show you an example. Below is an activity in Android in Java to show off accessibility features (from https://github.com/googlesamples/androi … y/#readme) (comments excluded for brevity):

package com.example.android.basicaccessibility;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
public class DialView extends View {
    private static int SELECTION_COUNT = 4;
    private static float FONT_SIZE = 40f;
    private float mWidth;
    private float mHeight;
    private float mWidthPadded;
    private float mHeightPadded;
    private Paint mTextPaint;
    private Paint mDialPaint;
    private float mRadius;
    private int mActiveSelection;
    public DialView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    private void init() {
        mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint.setColor(Color.BLACK);
        mTextPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mTextPaint.setTextAlign(Paint.Align.CENTER);
        mTextPaint.setTextSize(FONT_SIZE);
        mDialPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mDialPaint.setColor(Color.GRAY);
        mActiveSelection = 0;
        setOnClickListener(()->{
                mActiveSelection = (mActiveSelection + 1) % SELECTION_COUNT;
                sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
                invalidate();
        });
    }
    @Override
    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        super.onPopulateAccessibilityEvent(event);
        int eventType = event.getEventType();
        if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED ||
                eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
            event.getText().add("Mode selected: " + Integer.toString(mActiveSelection + 1) + ".");
            event.setItemCount(SELECTION_COUNT);
            event.setCurrentItemIndex(mActiveSelection);
        }
        if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
            event.getText().add("Tap to change.");
        }
    }
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        float xPadding = (float) (getPaddingLeft() + getPaddingRight());
        float yPadding = (float) (getPaddingTop() + getPaddingBottom());
        mWidth = w;
        mHeight = h;
        mWidthPadded = w - xPadding;
        mHeightPadded = h - yPadding;
        mRadius = (float) (Math.min(mWidth, mHeight) / 2 * 0.8);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(mWidth / 2, mHeight / 2, (float) mRadius, mDialPaint);
        final float labelRadius = mRadius + 10;
        for (int i = 0; i < SELECTION_COUNT; i++) {
            float[] xyData = computeXYForPosition(i, labelRadius);
            float x = xyData[0];
            float y = xyData[1];
            canvas.drawText(Integer.toString(i + 1), x, y, mTextPaint);
        }
        final float markerRadius = mRadius - 35;
        float[] xyData = computeXYForPosition(mActiveSelection, markerRadius);
        float x = xyData[0];
        float y = xyData[1];
        canvas.drawCircle(x, y, 20, mTextPaint);
    }
    private float[] computeXYForPosition(final int pos, final float radius) {
        float[] result = new float[2];
        Double startAngle = Math.PI * (9 / 8d);   // Angles are in radiansq
        Double angle = startAngle + (pos * (Math.PI / 4));
        result[0] = (float) (radius * Math.cos(angle)) + (mWidth / 2);
        result[1] = (float) (radius * Math.sin(angle)) + (mHeight / 2);
        return result;
    }
}

And here it is in Scala:

package com.example.android.basicaccessibility
import android.annotation.TargetApi
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.os.Build
import android.util.AttributeSet
import android.view.View
import android.view.accessibility.AccessibilityEvent
import DialView._
object DialView {
  private var SELECTION_COUNT: Int = 4
  private var FONT_SIZE: Float = 40f
}
class DialView(context: Context, attrs: AttributeSet) extends View(context, attrs) {
  private var mWidth: Float = _
  private var mHeight: Float = _
  private var mWidthPadded: Float = _
  private var mHeightPadded: Float = _
  private var mTextPaint: Paint = _
  private var mDialPaint: Paint = _
  private var mRadius: Float = _
  private var mActiveSelection: Int = _
  init()
  private def init(): Unit = {
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG)
    mTextPaint.setColor(Color.BLACK)
    mTextPaint.setStyle(Paint.Style.FILL_AND_STROKE)
    mTextPaint.setTextAlign(Paint.Align.CENTER)
    mTextPaint.setTextSize(FONT_SIZE)
    mDialPaint = new Paint(Paint.ANTI_ALIAS_FLAG)
    mDialPaint.setColor(Color.GRAY)
    mActiveSelection = 0
    this.onClickListener = () => {
      mActiveSelection = (mActiveSelection + 1) % SELECTION_COUNT
      sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED)
      invalidate()
    }
  }
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  override def onPopulateAccessibilityEvent(event: AccessibilityEvent): Unit = {
    super.onPopulateAccessibilityEvent(event)
    val eventType: Int = event.getEventType
    if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED ||
        eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
      event.getText.add("Mode selected: " + java.lang.Integer.toString(mActiveSelection + 1) +".")
      event.setItemCount(SELECTION_COUNT)
      event.setCurrentItemIndex(mActiveSelection)
    }
    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
      event.getText.add("Tap to change.")
    }
  }
  protected override def onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int): Unit = {
    val xPadding: Float = (getPaddingLeft + getPaddingRight).toFloat
    val yPadding: Float = (getPaddingTop + getPaddingBottom).toFloat
    mWidth = w
    mHeight = h
    mWidthPadded = w - xPadding
    mHeightPadded = h - yPadding
    mRadius = (Math.min(mWidth, mHeight) / 2 * 0.8).toFloat
  }
  protected override def onDraw(canvas: Canvas): Unit = {
    super.onDraw(canvas)
    canvas.drawCircle(mWidth / 2, mHeight / 2, mRadius.toFloat, mDialPaint)
    val labelRadius: Float = mRadius + 10
    for (i <- 0 until SELECTION_COUNT) {
      val xyData: Array[Float] = computeXYForPosition(i, labelRadius)
      val x: Float = xyData(0)
      val y: Float = xyData(1)
      canvas.drawText(java.lang.Integer.toString(i + 1), x, y, mTextPaint)
    }
    val markerRadius: Float = mRadius - 35
    val xyData: Array[Float] = computeXYForPosition(mActiveSelection, markerRadius)
    val x: Float = xyData(0)
    val y: Float = xyData(1)
    canvas.drawCircle(x, y, 20, mTextPaint)
  }
  private def computeXYForPosition(pos: Int, radius: Float): Array[Float] = {
    val result: Array[Float] = Array.ofDim[Float](2) // Angles are in radiansq
    val startAngle: java.lang.Double = Math.PI * (9 / 8d)
    val angle: java.lang.Double = startAngle + (pos * (Math.PI / 4))
    result(0) = (radius * Math.cos(angle)).toFloat + (mWidth / 2)
    result(1) = (radius * Math.sin(angle)).toFloat + (mHeight / 2)
    result
  }
}
"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

16

[wow]. Scaler seams to me a bit similar to Kotlin which is now officially supported by Google in Android Studio 3. I haven't compared yet those two languages though.

Thumbs up

17

The one time picking the "right" language does matter is if you are planning to code as a job. In that case, you will want to get a feel for what languages are being used for the types of jobs you want. For example, both Java and Scala are mentioned above. If you are programing for yourself, either would be fine. If you are wanting a job, it is probably easier to find a job if you know Java. However, at the same time, once you develop the coding mindset and learn one language, it becomes easier to learn another language and to pick up any differences in the coding mindset for that language. SO, once you become comfortable with Python, you can try other languages. You won't be as proficient with those new languages at first, but you will develop your prficiency faster with a second language--if you put in the time. PS: I'm not saying that Scala or Java are bad languages. Personally, I am language agnostic and will learn to code in whatever language seems enjoyable at the time or that will pay me.

Thumbs up +1

18

Hector does have a point. Once you learn, say, Python, learning other programming languages is far easier. They all have the same things: conditional statements, functions, variables, constants, etc. Other languages, though, might have more features than another: Python has import declarations, modules, attributes, classes, objects, and C interopperability; while C has procedural functions, variables, constants, assembly language interopperability, custom type definitions, a preprocessor, etc. But, if you break down all the programming languages in the world, they all have the same things. It's like learning a real-life language, though all real-life languages are different than one another, and have little in common.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up +1

19

Thanks a ton for all your awesome answers. It all makes great sense. Well, I'll keep learning and hope I get something out of this... big_smile

Best regards SLJ.
If you like the post, then please give it a thumps up.
Feel free to contact me privately if you have something in mind. If you do so, then please send me a mail instead of using the private message on the forum, since I don't check those very often.
Happy gaming... :D

Thumbs up

20

Hi SLJ
although I've tried bgt but yet I am figuring the sintacs.
python is somehow easier than bgt in its basic fundaments.
but the thing is that I 've left the programming quite a while ago so I am not in a regular practice.
best of luck for you.
Thanks
Ishan

life's battle do not always go to the stronger and faster man,
But sooner or later who win the one who thinks he can!

Thumbs up