Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Real World Programming: Calculating Complexity

 
Ranch Hand
Posts: 117
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I have no industry exposure to programming yet , so I would like to know the following information, from the people on this forum especially those who have experience in programming for years.

How is complexity calculated for the programs developed by the programers ? when each of them write really complex and long code modules, will they be able to manually to calculate the time complexity of their programs , to ensure that it is optimal code. or is there any software to do this or is this role assigned to someone else ?

at times the complexity calculation involves lot of complex mathematical steps to derive the complexity , so in such cases should the developers themselves do it manually, along with their programming task also ?
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never, in 40 years of programming, calculated the time complexity of any code. Testing shows whether the code has performance issues or not. If it has no issues, it's good. If it has issues, the algorithms are evaluated and refactored.

Always avoid premature optimization.
 
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of us already know the complexity of the algorithms we are using, for example merge sort is O(nlogn) complexity and bubble sort runs in O(n²) complexity. Some methods shown in the standard API declare their complexity, too, as you will see if you go through classes like ArrayList. Remembering that the overall complexity of a program is determined by its slowest step, like the weakest link in a chain, it is often only necessary to find the slowest algorithm.

Don't go to endless trouble to speed up your code; don't do anything until it is running and there seem to be problems about it running too slowly. Then don't try to sort out the problem by hand because chances are you'll get it wrong.
 
Lilou Laure
Ranch Hand
Posts: 117
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.so when they are evaluated , are software tools also used, or is it done manually completely ?

2.and if there seems to be an issue of higher time complexity , how is a solution with lower / acceptable complexity created ?
 
Lilou Laure
Ranch Hand
Posts: 117
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Then don't try to sort out the problem by hand because chances are you'll get it wrong.



then how is one supposed to sort out the problem ?    are there any software tools available ?
 
Campbell Ritchie
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lilou Laure wrote:then how is one supposed to sort out the problem ?

With a stopwatch; if you can calculate 1,000,000 results in 1″, you probably don't have a problem.

   are there any software tools available ?

Yes; the best known are called profilers. They are actually programmed to look for where your code is running the most slowly.
 
Lilou Laure
Ranch Hand
Posts: 117
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there something to suggest possible solutions to make the code run faster in case it is slow ? I mean not just highlighting where it is slow, but also what could be the probable solution or a hint  to resolve that ? or does that part of it have to be done ourselves ?
 
Marshal
Posts: 25837
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When part of your program is running slowly and that affects the response time of the program in a substantially negative way (i.e. people start complaining, or response times guaranteed in a contract are exceeded, or something like that) then you have to look at that part of the program and see what can be done about speeding it up.

It's not really possible to suggest possible solutions because that question basically amounts to "How do I fix a problem?" However in this particular case it often happens that improving the hardware on which the code runs can be part of the solution. Or the speed of the network. Or the design of the database from where the data comes. Or the expectations of the users, for that matter. ("Look, you've asked the system to generate a 6,000-page PDF, you can't reasonably expect that to happen immediately.") There's all kinds of possibilities.

And also, looking at the code and noticing that part of it is implemented by an O(N^2) algorithm isn't the right approach. It may be that the code in question never has N greater than 10, for example, in which case that information is likely to be useless.
 
Lilou Laure
Ranch Hand
Posts: 117
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks for the answers !

in the field of developing/coding/programming, eventually does a programmer get used to his/her job and does it seem to be easier at  a later stage ?
 
Paul Clapham
Marshal
Posts: 25837
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and no. Yes, after you've been working at a job for a few years you would normally get used to it, and you'd expect it to get easier. But on the other hand the programming field changes very rapidly, so it can happen that your job changes rapidly as well. That's not always the case, though, I hear there are still a few people still working on COBOL applications somewhere out there.
 
Lilou Laure
Ranch Hand
Posts: 117
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But we will find the following easy ? the technique of creating code for a solution , or the kind of approach to be used to solve a problem or ways to solve a problem , playing with data structures quite easily, etc.
 
Campbell Ritchie
Marshal
Posts: 70370
283
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that question difficult to understand. None of those things is easy, but anybody who is any good will become more competent with practice.
 
Lilou Laure
Ranch Hand
Posts: 117
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all !
 
Saloon Keeper
Posts: 12295
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done it at my job a couple of times, but only AFTER we found that certain parts of the code were running slower than expected. First you run a profiler to identify the parts of the code that take up a lot of time, and then you see if you can't reduce the complexity of algorithms you used.

Note that when you use the word 'complexity', it can mean many different things. At first I thought your question was about cyclomatic complexity, which has different calculation rules associated with it, and tools exist to calculate this for your methods.
 
Marshal
Posts: 15896
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difficulty in programming is not so much in writing code as it is in writing clean, maintainable code. There are literally millions of programmers in the world now being paid to write code. Of that population, a relatively small fraction of it knows how to write and maintain clean code. In all my years (almost 30 now) of professional programming, I have never seen any code base move towards a cleaner state without conscious and deliberate effort by the developers. The Law of Entropy applies just as well to software as it does to the physical world. The work you must put into a software system to keep its entropy low is what is hardest about professional software development and it never seems to get easier unless you stay on top of things all the time.
 
Junilu Lacar
Marshal
Posts: 15896
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, I think what separates the small fraction from the majority of programmers/developers is the difference between just writing code and actually designing systems. Good programmers are really good designers at their core. It all goes back to the thesis that the code is the design that Jack Reeves wrote three essays about. Programmers who just write code without giving much thought to clean design are usually the ones who make a lot of problems not only for themselves but for everyone else involved with the software system they "help" create.
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic