Author Topic: how to build programming logic?  (Read 12965 times)

0 Members and 3 Guests are viewing this topic.

Offline shivajikobardanTopic starter

  • Contributor
  • Posts: 23
  • Country: np
how to build programming logic?
« on: December 17, 2021, 09:35:54 am »

I am computer engineering student(Our curriculum is 80% similar to electronics engineering in our country so you can call me electronics engineering student as well tbh). But this thing is relevant to electronics engineering as well so I am asking it here. I still don't know how to program. I of course can code very tiny tiny programs like prime number etc etc...But I am nowhere near the level of building big programs like using frameworks to make stuffs and so on.

I learnt c, c++ and python and bit of javascript. But all of them were useless. I learnt programming languages and not programming.

I know assebly language coding in 8085 and 8086 microprocessor. I didn't learn 8051 quite well though.

I think this question is relevant to electronics engineering students in my country(Nepal) as most electronics engineering students pursue career in coding like web development. Any way, coding is essential part of electronics engineering, we all know about that.


I am currently learning python. I learnt syntax of python. And I am currently solving codewars problems. I read other person's solutions as well and try to understand at least 5 different solutions to a problem. My logic has improved a bit in programming but I consciously want to know how to improve my logic in programming? What else can I do to improve my logic in programming? Any guidance will be extremely valuable.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15420
  • Country: fr
Re: how to build programming logic?
« Reply #1 on: December 17, 2021, 05:33:06 pm »
I learnt c, c++ and python and bit of javascript. But all of them were useless. I learnt programming languages and not programming.

I think this is a pretty interesting point you have there. I wish more students saw it the way you do!

What else can I do to improve my logic in programming? Any guidance will be extremely valuable.

Learn algorithmics. Read "The Art of Computer Programming" (D. Knuth). Invaluable.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8833
  • Country: fi
Re: how to build programming logic?
« Reply #2 on: December 18, 2021, 12:31:22 pm »
Remember that data structures are everything. The code that processes the data, or logic, is only secondary.
 

Offline Jan Audio

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: how to build programming logic?
« Reply #3 on: December 21, 2021, 04:18:29 pm »
Did you try make a game ?
The most complicated thing you can do.
 

Offline AntiProtonBoy

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: au
  • I think I passed the Voight-Kampff test.
Re: how to build programming logic?
« Reply #4 on: December 22, 2021, 04:38:54 am »
I learnt c, c++ and python and bit of javascript. But all of them were useless. I learnt programming languages and not programming.
Learning how tools work is quite valuable. Now you have to find a purpose to actually use them. The best way to learn programming is by actually doing it. Just write toy programs, like a ray tracer that dumps a rendered image to disk. Ray tracers are a great example, as it forces you to think about data structures, algorithms, interfacing with libraries, memory management, mathematics and you get fun visual results.

 

Offline hli

  • Frequent Contributor
  • **
  • Posts: 259
  • Country: de
Re: how to build programming logic?
« Reply #5 on: December 22, 2021, 12:35:07 pm »
'Advent of code' is also quite nice to learn. The tasks get progressively harder. There is a reddit with discussions about the problems and the possible solutions, which can help in understanding how to solve the problems.

Learning programming is mostly learning problem solving, and learning micro-skills (although the former might just be a case of the former).
For problem solving, you need to learn how to
  • understand problems
  • structure the problem, and split it into smaller problems, so you can make progress
  • prove your proposed solutions work
  • debug when the solution does not work
Micro-skills are what you might call 'tricks of the trade', but are mostly the small skills that help to get things done faster / more efficiently. In term of computer programming these are
  • algorithms (no need to know them all, but which exists and where to find them, and how to implement them if needed)
  • data structures, and the tasks for which they are suited
  • learn how to parse arbitrary inputs into your data structures
  • the usual patterns of your programming language (so you can understand others code)
  • the usual libraries for your programming language, an when they are used best
  • know how to use StackOverflow (and how to search for solutions for your problems)
I come to think that the problem solving skill is something that you learn quite early in your life, whereas the micro-skills come with experience.
 
The following users thanked this post: bpiphany

Offline cfbsoftware

  • Regular Contributor
  • *
  • Posts: 123
  • Country: au
    • Astrobe: Oberon IDE for Cortex-M and FPGA Development
Re: how to build programming logic?
« Reply #6 on: December 23, 2021, 05:10:26 am »
I recommend you read some books on the subject. Some classic examples to get started with are:

Programming Pearls by Jon Bentley
Code Complete by Steve McConnell
Chris Burrows
CFB Software
https://www.astrobe.com
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6952
  • Country: fi
    • My home page and email address
Re: how to build programming logic?
« Reply #7 on: December 23, 2021, 05:19:23 am »
What else can I do to improve my logic in programming?
Learn problem-solving strategies and methods in general.

In a very real sense, as a programmer, we describe problem solving strategies and algorithms for a computer to apply.

I've found that the code per se is not nearly as important as the data structures, strategies, and algorithms.
Pay attention to the comments you write.  They should not describe what the code does (because we can read the code itself just fine), but your intent and/or reasoning behind the code.  Commenting and documenting a project is sometimes worth more in the long run that the code itself.

When the logic, the problem solving stategies and algorithms and data structures are known, the code is relatively straightforward to write: the "problem has already been solved".
 

Offline Picuino

  • Super Contributor
  • ***
  • Posts: 1033
  • Country: es
    • Picuino web
Re: how to build programming logic?
« Reply #8 on: December 23, 2021, 10:22:17 am »
 

Offline Picuino

  • Super Contributor
  • ***
  • Posts: 1033
  • Country: es
    • Picuino web
Re: how to build programming logic?
« Reply #9 on: December 23, 2021, 10:25:26 am »
Another book that I would have loved to know when I started learning to code.

Clean Code: A Handbook of Agile Software Craftsmanship
https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

https://enos.itcollege.ee/~jpoial/oop/naited/Clean%20Code.pdf
 

Offline Jan Audio

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: how to build programming logic?
« Reply #10 on: December 23, 2021, 05:19:02 pm »
the "problem has already been solved".

shivajikobardan needs some problems first.
And to write bad code so next time wont make the same mistake = learning.
Really that code you mention is invisible and makes no sense, is no learning.
shivajikobardan if you hurry you can program good in 10 years,
just like animal code.
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6952
  • Country: fi
    • My home page and email address
Re: how to build programming logic?
« Reply #11 on: December 24, 2021, 01:43:07 am »
the "problem has already been solved".
shivajikobardan needs some problems first.
Agreed.  I perhaps worded myself badly, but I meant that choosing the data structures and algorithms, and finding the exact math (equations et cetera) needed, is at the heart of writing programs.  When I create a program, I do not worry about what the code needs to do – because that becomes clear as the solution reveals itself –, but what kind of data structures and algorithms I need.  Since each problem has many different solutions, finding a "good" one, an "efficient" one, is a general problem solution skill.

Thus, finding interesting problems to work on, and working out exactly how (and why choose that particular way) they are solved using programming, is the key.
Knowing a programming language is one step.
Knowing problem-solving methods and techniques, is more important; and in my opinion, is not discussed enough.
Which is why I suggested to learn about problem solving in general – which in itself is an art, I claim, and useful for all programming tasks.

Even as a kid, I personally liked descriptive geometry, especially the math of how 3D objects, surfaces, etc. can be visualised.  That lead me to basic vector algebra, linear algebra, and unit quaternions (or bivectors, whichever you prefer) to describe orientations and rotations.  I'm curious, but I learn things better when I need to apply them to do something.

Visual things are often "more fun" than non-visual things.  So, working out how e.g. graphical user interfaces are properly implemented, and creating a program that interactively draws fractals, can be lots of fun.  The math itself is simple, but the details can be frustrating, because every single pixel in the image has to be separately handled, and you probably need parallel programming (via threads or processes) to keep the user interface responsive while the image is still being generated.

I also like puzzles, and have used e.g. graph analysis to find solutions to puzzles.  Graphs, trees, heaps, and disjoint set data structures have all been very useful to me.  To help me visually see the data structures, my test programs save the structure in the Graphviz DOT language (a text language describing graphs) that I then visualize with Graphviz tools, most often dot.

Games are fun, too.  I do believe my first self-designed one was a typical run-and-jump one on Commodore 64, of a runner trying to jump over a hurdle when the space bar was pressed, written in basic.  Not too far from Flappy Bird, really.  One can start with Curses – or specifically ncursesw, which is included in all Linux distributions, and available for all OSes – for text-mode graphics and interactive keyboard input, to make text-mode games like old Nethack.  The w version refers to "wide", which means it uses wide characters and strings, and allows one to use basically all Unicode glyphs in the text interface.  In Linux, it works extremely well.  Then, there are things like SDL library, with which one can create "proper" games.  UI toolkits like Qt, GTK+, TkInter, FLTK, and others provide a way to create proper graphical user interface programs in a portable fashion, not tied to a particular operating system like Windows, MacOS, or Linux.

I also like playing with sounds.  One of my favourite programs on my first PC, a Hyundai 80286, was written in Borland Pascal, and used the internal speaker (a single-tone beeper!) on the computer to emulate the sound of a toilet flushing.  I did not set out to create it, just happened on it by accident, then refined it.  Later in life, as part of my computational materials physics background, I delved into molecular visualization and sonification (describing what happens in an atomic simulation by generating descriptive sounds).

Tools are always nice.  One can never have too many tools.  It is useful to know more than one programming language, so that one can implement a tool in the one that makes most sense.  A while ago, as a result of a discussion here at EEVBlog, I created this example FIR filter response analysis page, as an example of a self-contained HTML+CSS+JavaScript tool, that can be either hosted on the net, or saved to your local computer and used locally without any internet connection.  It is a good example of choosing the proper tool (language/environment), as the entire thing is just 372 lines (most of which is the visual HTML and CSS stuff).  It is not complete, though, as it was only an example of how such things could be done.

Understanding different programming paradigms is very important, though.  For JavaScript on web pages, we use event-driven programming, because that's how the Document Object Model, the "glue" between HTML and CSS visual description and JavaScript works.  Similarly with UI toolkits like Qt and Gtk+.  But for SDL and Curses, we are fully in control, in imperative fashion, of the entire display and refresh loop; as is usual when creating games.

It is not good to specialize early on something.  Working on wildly different things exposes you to more ideas, more models, more paradigms, and therefore more problem solving methods, which are definitely needed when you build your developer career.  Every week, I still use several different programming languages – shell (my choice is usually Bash, but I do sometimes use Dash, a POSIX shell), awk, C, Python; others vary from week to week depending on what I'm working on – and every week, I learn more.  I myself am still learning.  One of the things I wish I had learned better early on, is to write better comments: I still need to work a lot on that.

Making errors is often the most interesting facet, if you take the time to find out what went wrong, and why.  (I absolutely hate the "stick spaghetti to the wall, and see what sticks" attitude, when someone says that "this fixed it, but I don't know why".  To me, it feels like reading a detective story that ends with somebody going to jail but no evidence presented that they were actually the perpetrator.  Unsatisfying.)  I suspect that the most interesting things I know, I learned by making errors.  It is uncomfortable and sometimes painful to err, definitely, but it just makes the satisfaction of solving the problem or completing the work so much more rewarding in the end.

If your personal path is different, don't worry: most paths differ.  Just enjoy every step of the way, because the path itself is the purpose and end goal.  You are never "done" or "finished learning": there is always something new to discover, learn, invent, solve, or ask.

Oh, and apologies for the wall of text.  My excessive verbosity is another thing I'm still working on. :)
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4533
  • Country: nz
Re: how to build programming logic?
« Reply #12 on: December 24, 2021, 04:36:07 am »
On a small scale, learn how to design loops that work and are not buggy. Learn about preconditions and postconditions and loop invariants and weakest-preconditions. A lot of academic work was done around this 40 years ago. Learn how to use recursion well. Contrary to popular belief, it is easier to reason about and prove recursion than iteration.

Learn how the structure of code matches the structure of the data. Wirth's book "Data Structures + Programs = Algorithms" is still worth reading.

Although it was designed for COBOL and business applications in the days of punched cards and magnetic tapes, Michael A. Jackson's "Jackson Structured Programming" has some interesting and useful insights into how to constructively design your program structure based on the (maybe complex) structure of the data it processes. It is still useful today for thinking about programs that deal with files, network streams, structuring multiple programs or threads that communicate via FIFOs etc. https://en.wikipedia.org/wiki/Jackson_structured_programming

 
The following users thanked this post: paf

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4247
  • Country: gb
Re: how to build programming logic?
« Reply #13 on: December 24, 2021, 01:57:15 pm »
I learned c, c++ [...] I learned programming languages and not programming.

I can say, after ~25 years of experience as a paid engineer, I still don't know *how to program*, I only know *how to solve some problems*, not all kinds of problems, only a few classes of problems.

The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 
The following users thanked this post: barycentric

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6789
  • Country: ro
Re: how to build programming logic?
« Reply #14 on: December 24, 2021, 02:22:12 pm »
I learnt c, c++ and python and bit of javascript. But all of them were useless. I learnt programming languages and not programming.
...
I am currently learning python. I learnt syntax of python. And I am currently solving codewars problems. I read other person's solutions as well and try to understand at least 5 different solutions to a problem. My logic has improved a bit in programming but I consciously want to know how to improve my logic in programming? What else can I do to improve my logic in programming? Any guidance will be extremely valuable.

Also, from a hardware perspective and related to the "programming logic" words you mentioned in the title, you may want to read about "state machines".  Often, State Machines are rather neglected in software/programming-like classes.  I've only noticed "state machines" theory as important only very late, when starting to fool around with FPGAs.

Now I think State Machines should be stressed more while learning software.  It is very unfair that State Machines is often taken lightly in software, and studied deeper only when it came to digital-design/FPGAs/hardware topics.

You mentioned Nepal, but I think such "programming" pitfalls are everywhere.  Though, I'm not a software developer, I'm from the hardware side, so I might be all wrong talking about software.

Not sure how much might help, there is a YouTube channel from a dude that put State Machines in the center of his attention, mostly presented as ARM programming classes, but he developed a State Machines based programming tools and style:
https://www.youtube.com/channel/UCMGXFEew8I6gzjg3tWen4Gw
« Last Edit: December 24, 2021, 02:25:00 pm by RoGeorge »
 
The following users thanked this post: Ian.M

Offline bobcat2000

  • Regular Contributor
  • *
  • Posts: 218
  • Country: us
Re: how to build programming logic?
« Reply #15 on: December 26, 2021, 08:53:13 pm »
Quote
My logic has improved a bit in programming but I consciously want to know how to improve my logic in programming? What else can I do to improve my logic in programming?

I think you are taking the wrong classes.  If I remember correctly when I was in school, my programming classes taught very little programming.  Majority of the classes taught math.  LOT OF MATH.  My homework were full of Calculus calculations.  Networking classes were nothing but math.  AI classes were math.  Programming were even more math.

So, I think the school has already figured out how to "improve your logic in programming".  MATH!!!

P.S. Hey! I got an A in this project ;)

 
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9935
  • Country: us
Re: how to build programming logic?
« Reply #16 on: December 26, 2021, 09:50:10 pm »

Learn how the structure of code matches the structure of the data. Wirth's book "Data Structures + Programs = Algorithms" is still worth reading.


That is my all-time favorite book and Pascal will always be my favorite language.

The PL0 tiny pascal compiler/run time in the back of the book is excellent and demonstrates many of the ideas previously presented.  I have coded that thing a half dozen times since I started with UCSD Pascal back around '80 or so.  I also translated the code to Fortran.  Pascal took 6 pages, Fortran took 54 pages.  Now, I'll concede the Fortran interpretation was crap but, really, sets aren't much fun in Fortran and that compiler project uses set operations all over the place.

In the end, programming is about the data more than the code.  How data comes in, what data is coming, how is the program to respond to the data and what should it output.  If you get the data structures right, selecting algorithms and writing code is fairly straightforward.  If the data structures are wrong, you will forever be putting lipstick on a pig.

One thing that Wirth points out in the book is the inadvertent use of null pointers.  Over and over, he shows how to make the mistake and how to prevent it.  C programmers are notorious for trying to reference through a null pointer but I suppose it is common to other languages as well.  Just something to keep in mind when using linked lists.

One of the problems I have with learning new languages is that the book authors show little ideas but there is no overarching project.  I would really like to see a book on C++ that starts with the definition of a fairly large project and works up the code, piece by piece.  It needs to be a large enough project to use all of the language features that are described in the book.  I'm thinking about 10,000 lines or so of something that could be useful.

I realize this is a great deal more difficult than simply writing about classes in the abstract.  Here's a class, here's the member functions, here's the public and private data; this is all pretty easy.  But it simply doesn't tie anything together.

 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15420
  • Country: fr
Re: how to build programming logic?
« Reply #17 on: December 26, 2021, 10:18:33 pm »
In the end, programming is about the data more than the code.  How data comes in, what data is coming, how is the program to respond to the data and what should it output.  If you get the data structures right, selecting algorithms and writing code is fairly straightforward.  If the data structures are wrong, you will forever be putting lipstick on a pig.

Since the "computing world" is notorious for running in circles, you won't be surprised to know that "data-oriented programming" is now depicted as the new shiny paradigm, while it was already known decades ago.
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4247
  • Country: gb
Re: how to build programming logic?
« Reply #18 on: December 27, 2021, 11:13:18 am »
In the end, programming is about the data more than the code.  How data comes in, what data is coming, how is the program to respond to the data and what should it output.  If you get the data structures right, selecting algorithms and writing code is fairly straightforward.

That's what(Software) Design is for, a process to transform user requirements and constraints into some suitable form, which helps the programmer in software coding and implementation.

design ( requirements, constraints ) -> { programming -> coding -> { implementation, testing } }

Quote
If the data structures are wrong, you will forever be putting lipstick on a pig

I love this expression  ;D ;D ;D
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline Jan Audio

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: how to build programming logic?
« Reply #19 on: December 27, 2021, 03:56:45 pm »
Basicly what they say at the university here : You have internet go find out how it works.
 

Offline emece67

  • Frequent Contributor
  • **
  • !
  • Posts: 614
  • Country: 00
Re: how to build programming logic?
« Reply #20 on: December 27, 2021, 04:45:52 pm »
.
« Last Edit: August 19, 2022, 04:56:41 pm by emece67 »
 

Offline MarkMLl

  • Frequent Contributor
  • **
  • Posts: 366
  • Country: gb
Re: how to build programming logic?
« Reply #21 on: December 29, 2021, 01:57:38 pm »
I learnt programming languages and not programming.

If you already realise that, then you've learnt more than most "experienced professionals".

Apart from the excellent points being made by everybody else, I always maintain that a reasonable command of computer hardware and architecture is an enormous aid to understanding software, and a reasonable command of software engineering is an enormous aid to understanding hardware. It's most unfortunate that most curriculums keep the disciplines separate and turn out graduates with deep proficiency in one language or technique rather than adaptable generalists.

But because software tools, documentation and papers are more readily accessible than large-scale hardware design and testing tools, it's arguably easier for a competent engineer to develop software skills than for a programmer to achieve competence in hardware.

MarkMLl
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15420
  • Country: fr
Re: how to build programming logic?
« Reply #22 on: December 29, 2021, 06:12:41 pm »
Basicly what they say at the university here : You have internet go find out how it works.

Oh yeah? So what is the university good for? Just deliver a degree? If so, I bet it could be done for much cheaper. :popcorn:
 

Offline Jan Audio

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: how to build programming logic?
« Reply #23 on: December 30, 2021, 01:38:13 pm »
Indeed you need the paper to get work mostly, not some working code.
I just like to say they cant help it either things go very fast, they cant offer you.

I stuck with my C++ and C thingie so i learned it, the university should also stay with something,
only it is easy to get distracted by other things, because internet is so big they want shit like java or safe languages that dont work fast,
and more modern things in the future also keep distracting because they dont know what to choose, logically.

Then you have the updates.
Creating a study cost about 10 years i heard, in 10 years its all outdated.
Note : i a have windows XP system, cant ask that from your students because microsoft say windows xp is a big virus.
« Last Edit: December 30, 2021, 01:53:49 pm by Jan Audio »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9935
  • Country: us
Re: how to build programming logic?
« Reply #24 on: December 30, 2021, 05:45:48 pm »
Does anybody use flowcharts anymore?  They were a big deal in the early '70s when I started programming and could be quite detailed.  IBM documentation often included machine printed flowcharts.

I still scribble them down from time to time depending on the complexity of the function I am writing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf