LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2024, 01:04 AM   #16
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled

I found it helpful to have small self-contained fragments of code to maintain ( if this is English ).
It does not help against ill-named variables, but it reduces their effect significantly. I am writing this because less strictly typed languages downright invite you to write comfortable code instead of watching efficiency. Especially when you confound data types in mixed structures, it can be *helpful* to re-use variable-names.

Scope is extremely important then.

Having given up all programming languages other than Ruby, I cannot but praise the object oriented way of thinking and coding with this language (and similar that I do not even know). In a procedural code, much of the charms of such a language become a curse and have to be avoided or watched very closely, which is *not* comfortable and bears other risks.

Last edited by Michael Uplawski; 02-10-2024 at 01:06 AM. Reason: Kraut2English
 
Old 02-10-2024, 01:49 AM   #17
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,580
Blog Entries: 19

Rep: Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453
I read somewhere that the near disaster on Apollo 13 was caused by a Fortran program in which a comma in the header of a loop was accidentally replaced by a stop (an easy mistake to make while typing). As a result, part of what should have been the loop control string became a decimal value and the initial do command merged with an earlier part of the control string to create a new variable to be set equal to that value. And of course the actual loop did not run.

But if that is true, then the real cause of the disaster was the Fortran compiler's readiness to accept an undeclared variable. If that had happened in a C program, the compiler would have flagged the error at once because decent programming languages don't allow undeclared variables.

Last edited by hazel; 02-10-2024 at 01:56 AM.
 
2 members found this post helpful.
Old 02-10-2024, 03:05 AM   #18
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,857

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
https://www.freecodecamp.org/news/cl...for-beginners/
 
Old 02-10-2024, 04:33 AM   #19
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,580
Blog Entries: 19

Rep: Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453
Two more things that I learned about programming in C:

1) The first time you compile a program, there are usually dozens of error messages and most of them roll off the top of the terminal. Do not be tempted to try to deal with the ones that still show. You will probably find nothing wrong with that code. Scroll back to the beginning and note the first error reported. If it is a true error and not just a warning, it will have prevented that line from being compiled, causing a cascade of derivative errors further down. Fix it (and any other obvious errors that you can see in that first few lines of output). Then run make again. There will be far fewer errors this time.

2) Never ignore the warning "Assignment makes x out of y without a cast", where x and y are variable types. Mostly warnings can be ignored but not that one. Because if you have really assigned an expression of type y to a variable of type x, it is far more likely that you have used the wrong variable name than that you forgot to do a formal type cast.

Last edited by hazel; 02-10-2024 at 04:37 AM.
 
Old 02-10-2024, 08:52 AM   #20
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
I've lately been playing with C++ for the Arduino (a package very-strangely named "Sloeber"), while creating a new and evil "gadget Geocache." I have definitely experienced the "error-message hemorrhage."

It can be the very slightest thing – and the "profusion of messages" might not point it out or even be relevant to the true problem. "It could be a comma ..." The error-messages are frankly "not very good at all." And, you see this a lot sometimes: it kinda feels like watching a car crash in slow motion . . .

I like to adopt the strategy of "compile often." Make a few changes, and hit compile. "The code isn't complete yet, but make sure it still compiles." If something goes bonkers, it's got to be related to what you just did, and it's best to catch that tpyo right away. (Read it again. Did you see the typo?)

I also use the git version-control system ... constantly. (This system is entirely file-based and does not require a "server." Thanks, Linus ...)

Make a little incremental change, get it to compile, and "commit." This now becomes a "very recent" point, at which you knew "everything compiled," that you can if necessary revert to. "Little baby steps." I also give each commit a meaningful one-liner description. If I'm exploring an idea that I might not want to keep, I "branch," and if I decide to keep it I "merge." git is faithfully tracking my every change, and giving me a reliable "way out."

(If the final code is going to be published to some repository somewhere, I use the rebase feature to "coalesce" my "many in-progress commits" to a single one that is more reasonable before pushing it. No one cares or wants to see how I "crawled" to get to the finish line.)

- - -

The first thing that I'd say to anyone who is "just getting into programming" is: "just persevere." Because, once you get the hang of it (and, you will ...), it's positively addictive. You are actually able to make "an over-glorified piece of sand, much smaller than your little fingernail," to do something useful. To do anything you like.

Last edited by sundialsvcs; 02-10-2024 at 09:08 AM.
 
1 members found this post helpful.
Old 02-11-2024, 08:14 AM   #21
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
I've lately been playing with C++ for the Arduino (a package very-strangely named "Sloeber"), while creating a new and evil "gadget Geocache." I have definitely experienced the "error-message hemorrhage."

It can be the very slightest thing – and the "profusion of messages" might not point it out or even be relevant to the true problem. "It could be a comma ..." The error-messages are frankly "not very good at all."
As I had been exposed to Web-Application development for longer than any living thing should be, I have become addicted to logging. Tracing a problem to its true origin is made in several ways, but until further notice, I will not take the cure.

Last edited by Michael Uplawski; 02-11-2024 at 08:15 AM. Reason: words
 
Old 02-11-2024, 08:25 AM   #22
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by hazel View Post
2) Never ignore the warning "Assignment makes x out of y without a cast" (...) it is far more likely that you have used the wrong variable name than that you forgot to do a formal type cast.
As far as I remember, there had *not once* been a cast missing, when the warning appeared in my compiler output.
 
Old 02-11-2024, 08:27 AM   #23
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,580
Blog Entries: 19

Rep: Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453
Quote:
Originally Posted by Michael Uplawski View Post
As far as I remember, there had *not once* been a cast missing, when the warning appeared in my compiler output.
In my case, it invariably meant that I had carelessly used the wrong variable name.
 
Old 02-11-2024, 09:32 AM   #24
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by hazel View Post
In my case, it invariably meant that I had carelessly used the wrong variable name.
That or I have really tried to assign incompatible variables, because one of the data-types was – truly – ill-chosen. It is funny, how this error does no longer occur with Ruby, but is replaced by others of more arbitrary type and consequence ... Duck-typing adds a lot of hilarity where other programming languages are just grim.
 
Old 02-12-2024, 03:24 AM   #25
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by sundialsvcs View Post
If the final code is going to be published to some repository somewhere, I use the rebase feature to "coalesce" my "many in-progress commits" to a single one that is more reasonable before pushing it. No one cares or wants to see how I "crawled" to get to the finish line.
I can see how you would use a git reset followed by a new commit to combine prior commits into a single entry but how do you do it with "rebase"? Did you misspeak and intend to say "reset", or am I missing a trick with "rebase"?
 
Old 02-12-2024, 07:56 AM   #26
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,603

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

See //www.git-scm.com/docs/git-rebase#_interactive_mode

Quote:
Rebasing interactively means that you have a chance to edit the commits which are rebased. You can reorder the commits, and you can remove them (weeding out bad or otherwise unwanted patches).

...

Sometimes the thing fixed in b.2. cannot be amended to the not-quite perfect commit it fixes, because that commit is buried deeply in a patch series. That is exactly what interactive rebase is for: use it after plenty of "a"s and "b"s, by rearranging and editing commits, and squashing multiple commits into one.
This is something that it's good to practice with on an unimportant/duplicated repository - the process is obvious when one understands it, but might be intimidating the first few times, so it's good to have the reassurance of being able to experiment with it not mattering if something screws up.

 
1 members found this post helpful.
Old 02-12-2024, 08:20 AM   #27
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Ahh, thanks.

I've only ever used a non-interactive rebase. I'll have to give this a shot.
 
Old 02-12-2024, 10:45 AM   #28
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Quote:
Originally Posted by GazL View Post
I can see how you would use a git reset followed by a new commit to combine prior commits into a single entry but how do you do it with "rebase"? Did you misspeak and intend to say "reset", or am I missing a trick with "rebase"?
The rebase command is used to interactively merge a number of commits into a single one. I did not use the wrong word. Just carefully read the docs and then try it. It's quite easy to do (correctly).

And – as it happens – I always "do 'git'" from the command-line. This keeps me from having to puzzle-out the "convenient" features of this-or-that editor. By now, "it is a reflex."

Last edited by sundialsvcs; 02-12-2024 at 10:48 AM.
 
1 members found this post helpful.
Old 02-12-2024, 10:54 AM   #29
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,857

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
rebase/cherry-pick/merge*is/are the most confusing part of a version control system. It helps to combine two (or more) parallel code modifications into one single change. But it's much easier to do it wrong than right (this is my own experience in a group with many people working on the same codebase implementing many different features).
 
2 members found this post helpful.
Old 02-12-2024, 05:37 PM   #30
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
I do use merge but I do not fool around with cherry-pick. There are plenty of aspects of git which are "well beyond my pay-grade."

Basically, I just do "a ton of in-progress commits," and then wrap all of them up into a single 'final' commit which I actually push public.

Every now and then, you simply "f!ck everything up," and what you want to do is: git reset --hard. Which is precisely what you do. Now you're miraculously teleported back to where you are once again on the diving board and you can decide what to do next. Older but wiser.

I use git for every project, even when there isn't any "external repository" and I never "push." What's priceless to me is that: "git doesn't need a server." (As I said: "Thanks, Linus! That's the second time you did something remarkable ...")

Last edited by sundialsvcs; 02-12-2024 at 05:41 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Linux kernel coders propose inclusive terminology coding guidelines, note: 'Arguments about why people should not be offended do not s LXer Syndicated Linux News 0 07-07-2020 10:36 AM
MIDI keyboard note-on and note-off inverted jakykong Linux - Software 0 08-21-2010 03:21 AM
Note for people using SSH from XP to Ubuntu aidansmoker Linux - Software 2 12-16-2007 03:16 AM
kind of a programming quesion...kind of not tho jhorvath Programming 2 06-30-2003 10:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration