Mistakes You Might Make As A Beginner Programmer

Advertisements

As a beginner in programming, you must fall into some errors that often result from any new start in a specific field. In fact, this is considered normal, and like other sciences that are the gateway to the world of modern technology, programming is considered one of the most important techniques that must be fully mastered and professionalized, and thus avoided. Making mistakes that novice programmers often make, which we will highlight in this article:

1) Haste and lack of concentration in writing the code:

It is not possible in any way to obtain a correct and accurate code that works on small and large applications if it had not been planned before with a lot of focus and accuracy. The stage of preparing the code must include important stages that must be studied on each one of them, which are in order: thinking, then research, then Planning, writing, verification, and modification if necessary.

Programming is not only just a code book, but also a technology that requires skill and creativity based on logic.

2) Not preparing an appropriate plan before commencing writing code:

As the absence of a general plan prepared for writing the appropriate codes is one of the most important factors of dispersion, so there must be no excessive planning in preparing the code, meaning that you do not need to exaggerate in preparing a model plan that consumes your time and effort, but rather it is sufficient to form a simplified idea through which you can start correctly and this It does not mean that you may not have to change the plan during work, but at least you have laid a correct foundation stone that you can rely on, whether to continue the work or amend it if necessary.

So, following this approach to planning makes it easier for you to act according to the requirements of the situation, such as adding or removing features that you did not think of in the first place, or fixing a defect somewhere, and this explicitly teaches you to be smooth and flexible in programming, ready to deal with any emergency circumstance.

3) neglecting code quality:

Coding quality is one of the most important pillars of writing correct code. Code is good when it is clear and readable. Otherwise, it turns into stale code.

Moreover, clarity of the code is the best way to properly form executable code and this is the primary task of the programmer

Any defect in the simplest things can prevent the code from working properly. For example, inconsistency with indentation and capitalization breaks the code from working, as shown in the example:

Also, long lines are usually difficult to read, so you should avoid exceeding 80 characters in each line of code.

In order to avoid making such errors, you can use the checking and formatting tools available in JavaScript, through which you can fix what can be fixed, so avoid yourself entering into mazes that are difficult for you to solve

The best option to maintain the quality of the codes for you is to know the most common errors and work to avoid them, including:

• Too many lines used in a file or function, breaking up long code into many smaller parts makes it easier for you to test each one separately

• Lack of clarity in naming short or specific variables

• Not describing the encoding of strings and raw numbers, and to avoid that, be sure to put the values indicating this encoding in a constant and give it an appropriate name

• Waste of time in dealing with simple problems that can be dealt with with a little skill and maneuvering in the use of appropriate abbreviations

• Neglecting appropriate alternatives that lead to ease of reading, such as exaggerated use in conditional logic

4) Haste to use the first solution:

This happens when the novice programmer searches for solutions that rid him of the problems he encounters, so he hastens to use the first solution he produces without taking into account the complications that will result that may hinder the correct programming and thus lead to failure, so the first solution is not necessarily the correct one.

Therefore, it is better to discover several solutions and choose the most appropriate one. Here, a very important point should be noted, which is that if you do not come up with several solutions to a problem, you are most likely unable to identify the problem accurately.

The evidence of the programmer’s skill lies in his choice of the simplest solution to address the problem, and not in his escape to the first solution he reaches in order to get rid of the problem immediately.

5) Sticking to the idea of the first solution:

Completely avoid sticking to the first solution, even if it requires more effort from you. When you feel doubt about the correctness of the solution, quickly get rid of the bad code and try to understand the problem and re-understand it more accurately, and always remember the skill is to get a simple solution that makes it easier for you to make appropriate decisions in dealing with the problem. You can also use source control tools such as GIT that provide many useful solutions

6) Rely on Google:

Beginner programmers often resort to solving some of the problems that they encounter while writing codes through the Google search engine. The problem that they faced may have faced many before them, so the solution is often present, and this actually saves some time in searching for a solution to the problem somewhat, and this is apparent, but have you thought This solution in the form of a line of code will continue with you as appropriate to your situation, be very careful not to use any line of code that is not clear to you and if you see it as the solution to your problem

7) Not using encapsulation:

Encapsulation is a system that works to protect variables in applications by hiding properties while maintaining the possibility of benefiting from them. This system is useful, for example, for making safe changes in the internal parts of functions without exposure to other parts. Neglecting the packaging process often leads to difficulty in maintaining systems

8) Wrong view of the future:

It is necessary for the programmer to have an insight and to study all the possibilities for each next step when writing code, and this is useful in testing advanced cases, but be careful not to let this view be your guide to implementing the expected needs by writing code that you do not need now, assuming that you can need it in the future Stay as consistent as possible with the style of coding you need in your day.

9) Use wrong data structure:

Determining the strengths and weaknesses of the data structures used in the programming language is evidence of the programmer’s skill and experience in this field. This point can be illustrated by some practical examples:

  • If we talk about the JavaScript language, we find that the array is the most used list, and the most used map structure is an object.
  • In order to manage the list of records, each record contains a specific identifier to search for, maps (objects) must be used instead of lists (arrays), and the use of numerical lists is the best option if the goal is to push values into the list

10) Turn your code into a mess:

In the event that there are codes that cause defects and irregularities in the code, they must be dealt with immediately and the resulting chaos removed, as in the following cases:

  • Duplicate code: This occurs when code is copied and pasted into a line of code, which leads to defects and irregularities resulting from code repetition.
  • Neglecting the use of the configuration file: If a certain value is used in different places in the code, this value belongs to the configuration file, to which any new value added to the code must belong anyway
  • Avoid unnecessary conditional statements (if): It is known that conditional statements are logic associated with at least two possibilities, and it is necessary to avoid unimportant conditions while maintaining readability, so what is meant here is that expanding the function with sub-logic follows a conditional statement (if) at the expense of Inclusion of another task causes unnecessary clutter and should be avoided as much as possible To clarify the issue of the conditional statement (if), consider this code:

Note that the problem is with the isOdd function, but have you noticed a more obvious problem?

The if statement is unnecessary, here is the equivalent code:

11) Include comments on understandable things:

It is necessary, even if it seems difficult at first, to avoid, as much as possible, including comments on understandable and obvious matters, as you can replace them with elements bearing names that are added to the code

For clarification, see the example with additional comments:

Notice the difference when writing the code without comments in this screenshot:

So, we noticed that listing names is more effective than including unimportant comments

However, this rule should not be generalized on the foundations of programming in general, but there are cases in which clarity is not complete without the inclusion of comments, in such cases you should structure your comments to know the reason for the existence of this code instead of a question and so on, even those who prefer to include comments We advise them to avoid mentioning the obvious matters, and to crystallize this idea more deeply, we note this example, which shows the presence of unnecessary comments:

Advertisements

12) Don’t include tests in your code:

Some programmers may think that they do not need to write tests in the code, and most likely they test their programs manually, and this may be out of their excessive confidence that they do not need to write tests in their code, but this cannot be considered negative at all because even if you want to know the mechanism Test automatically, you have to test it manually

If you pass an interaction test with one of your applications and want to perform the same interaction automatically next time, you must return to the code editor to add more instructions.

Here it should be noted that your memory may betray you in retrieving the test of successful checks after each change in the code, so assign this task to the computer and you only have to start guessing or creating your own checks even before writing the code. Development based on TDD testing, albeit not It is available to everyone but it positively influences your style which guides you to create the best design

13) Do you think that the task is going well?

Let’s see this image showing a function that implements the sumOddValues property. Does it have an error?

Have you noticed that the above code is incomplete, although it deals properly with certain cases, but it contains many problems, including:

First problem: Where does the null input handle?

There is an error that detects the function’s execution caused by calling it without arguments

There are two reasons why this erroneous code may occur:

• The details of your job implementation should not be shown to its users

• In the event that your job does not work with users and the error is caused by incorrect use, this will appear clearly, so you can program an exception thrown by the job, which the user refers to as follows:

 Better yet, you can avoid the error issue by programming your function to ignore null inputs

The second problem: wrong entries are not handled

See what the function will throw if the function is fetched with an object, string, or integer value:

Although array.reduce is a function

Anything that calls function (42) in our previous example is called an array inside a function because we named the function argument array so we noticed that the error says that 42.reduce is not a function

But maybe if the error appeared in the following form it would be more useful

It should be noted here that the aforementioned two problems are secondary errors that must be avoided intuitively, in addition to the existence of cases that require thinking and planning, as in the following example, which shows what will happen if we use negative values

The function here should have been called sumPositiveOddNumbers so that the previous line does not appear

The third problem: Not testing all the correct cases due to forgetting some exceptional cases.

The number (2) is included in the group even though it should not be in it

This problem appeared because reduce used only the first value in the collection as the initial value of the accumulator which is in our previous example number 2 so the solution here is that reduce accepts a second argument to be used as the initial value of the accumulator

This is where testing is necessary, although you may have discovered the problem when writing the code and including the tests with other operations

14) Exaggerated reassurance about the validity of current code

Some codes may seem useful to novice programmers, so they use them safely in their code, without knowing that sometimes they may be bad, but they were put because the developer was forced to put them in this way, causing problems for beginners, so it is necessary here to include a comment by developers targeting beginners to clarify There is a reason why this code is included in this way

Therefore, as a beginner, you should put any code that you want to use from another place into question until you understand what it is and why it exists in order to avoid making mistakes that you are indispensable for.

15) Extra care to use the ideal methods in programming

Although the ideal methods are called by this name, they do not always carry this meaning, and this happens when the novice programmer devotes most of his attention to following the ideal methods, or at least the methods that he deems ideal, ignoring some cases that require him to act differently to some of the basic rules in programming. Situations that will put you in front of a challenge that only your good behavior and skill that you will need to develop through dealing with these circumstances will save you.

16) The obsession with poor performance

To get rid of the obsession with fear of making mistakes during programming, always be careful from the beginning, with every line of code pay close attention and recall your information and skills that avoid you from making mistakes, but this concern to improve your performance before starting should not be exaggerated and good judgment before starting It is he who will help you to decide whether the situation is preparing to improve performance before starting, or that the improvement in some cases will be an unjustified waste of time and effort.

17) Not choosing user-friendly experiences

One of the characteristics of the successful programmer is that he always puts himself in the place of the user and looks at the application that he designed or developed from the user’s point of view. By adding them to your list of affiliate links, this helps a lot in getting better results

18) Disregard for users’ experience by developers

Each programmer has his own preferred method and tools in the programming process, some of them are good, some are less good, and some are bad, but in general, the tools used in programming can be called quality according to their locations. There are cases where the tools are good at a time when the same tools are bad in other places.

The novice programmer often prefers the widely circulated tools, regardless of their usefulness in his programming, as he is a novice programmer, but in order for this programmer to start moving to higher levels of experience, he must select tools based on their efficiency in addressing certain functions that require their use in the first place, so the programmer gains more openness And good behavior and gets rid of a problem that many suffer from, which is clinging to tools that they used to deal with in all cases.

19) Data problems caused by code errors

Data are the basic pillars that form the structure of programs, which are basically an interface for entering new information or deleting old ones from it. Therefore, the smallest error in the code will lead to an unexpected defect in the data, and this is what some novice programmers fall into if they sometimes use codes that they think have succeeded in Validation tests believe that a broken feature is not necessary The problem is exacerbated when the validation program continuously introduces data problems that were not understood from the beginning, causing it to accumulate until it reaches an irreversible level where it is impossible to restore the correct state. To avoid this problem, you can use Multiple layers of data validation, or at least the use of database-specific constraints, which we will now learn about when adding tables and columns to your database:

  • A NOT NULL constraint applied to a column means that null values are excluded from this column by specifying the field source as not empty in the database
  • A UNIQUE constraint applied to a column means that duplicate values are excluded within the entire table. This constraint is ideal for user tables related to entering data for a username or e-mail.
  • The CHECK constraint is a custom expression, and in order for data to be accepted, it must evaluate to true. This is ideal for a percentage column that contains integer values from zero to 100.
  • PRIMARY KEY constraint Each table in the database includes a key to identify its records, which means that the column values are not empty and also unique
  • The FOREIGN KEY constraint indicates that the column values must match the values recorded in another table column, which often represents a primary key.

One of the common problems experienced by beginners related to data integrity is the wrong handling of transactions. If a group of operations related to each other needs to change the data source itself, it must be wrapped in a transaction that allows it to be rolled back in the event of a defect or failure in one of these operations.

20) Create new programs wheel

In the world of programming, things change continuously and rapidly, and services and requirements are available in a way that exceeds the ability of the team to keep up with it as it should, and the wheel of programs is like these changing services, so you may not find what you need as a programmer in one of these wheels, so the invention of a new wheel seems inevitable, but in most cases if it exists If the standard wheel design meets your needs, it is best not to design a new wheel

There are many options for software wheels available online and you can try before you buy according to what you need and feature that enables you to see its internal design in addition to that it is free

21) The negative idea of code reviews

Beginner programmers often take a negative attitude towards code reviews, thinking that they are a criticism of them, but as a beginner programmer, if you adopt this attitude, you must completely change your view and invest in code reviews optimally, as it is your opportunity to learn and gain more experience. Every time you learn something new It will be of practical value to you in this field

On the contrary, if you look at the subject in a more comprehensive way, the code reviews may make mistakes and you correct yourself, and therefore you are facing an opportunity to teach and learn, and this in itself is a source of pride for you as a programmer, making your way towards professionalism.

22) Rule out the idea of using source control

One of the negatives that some novice programmers fall into is underestimating the strength of the source control system. Perhaps the reason is because they believe that source control is limited to presenting their changes to others and building on them, but the topic goes far beyond this idea. Commitment messages communicate your implementations as a novice programmer and use them to help supervisors to Your code needs to know how the code got to its current state

Another benefit of source control is the use of features such as scaling options, selective restore, store, reset, mod, and many other valuable tools for your encoding flow.

23) Minimize the use of the common country as much as possible

The common country is a source of problems and should be avoided as much as possible or at the very least reduce its use to the maximum extent, as the more global the scope, the worse the scope of this common condition, so new cases must be maintained in narrow ranges and it is necessary to ensure that they do not leak to the top

24) Not treating mistakes as useful

Many people hate seeing small red error messages while programming, but in fact, the appearance of errors indicates that you are getting more knowledgeable and getting to know more about the glitches that occur even with professional programmers, so you work to remedy them in the future.

25) Continuous and prolonged exhaustion

The novice programmer has an obsession that he must complete the work he is required to do, whatever the cost, and as soon as possible, and this is what drives him to work for long periods, forgetting that he needs rest. These long periods of sitting and thinking cause fatigue, and often the programmer, after long hours of work, reaches a stage where he has not He is no longer able to think even in front of the simplest things, so he stands helpless, so taking a break is necessary to restore mental activity and mental balance.

Advertisements

الأخطاء التي قد ترتكبها كمبرمج مبتدئ

Advertisements

كمبتدئ في البرمجة لابد وأن تقع في بعض الأخطاء التي تنتج غالباً عن أي انطلاقة جديدة في مجال معين و حقيقةً يعتبر هذا أمراً طبيعياً، وكغيرها من العلوم التي هي بوابة الدخول إلى عالَم التكنولوجيا الحديثة تعتبر البرمجة أحد أهم التقنيات التي يجب إتقانها واحترافها بشكل كامل وبالتالي تجنب الوقوع في الأخطاء التي غالباً ما يقع فيها المبرمجون المبتدئون والتي سنسلط الضوء عليها في مقالتنا هذه

1) التسرع وعدم التركز في كتابة الكود

لا يمكن بأي حالة من الأحوال الحصول على كود صحيح ودقيق يعمل على التطبيقات الصغيرة والكبيرة إن لم يكن قد خُطِّط له من قبل بكثير من التركيز والدقة فمرحلة إعداد الكود يجب أن تشمل مراحل هامة لابد من الوقوف على كل واحدة منها وهي بالترتيب: التفكير ثم البحث ثم التخطيط ثم الكتابة ثم التحقق ثم التعديل إذا اقتضى الأمر

فالبرمجة ليست فقط مجرد كتاب تعليمات برمجية فحسب ، بل هي أيضاً تقنية تتطلب المهارة والإبداع المستند إلى المنطق

2) عدم إعداد خطة مناسبة قبل الشروع في كتابة الكودات البرمجية

إذ أن غياب الخطة العامة المعدّة لكتابة الكودات المناسبة أحد أبرز عوامل التشتت لذا لابد من التخطيط غير المفرط في إعداد التعليمات البرمجية أي أنك لست بحاجة إلى المبالغة من إعداد خطة نموذجية تستهلك منك الوقت والجهد بل يكفي أن تكوّن فكرة مبسطة تستطيع من خلالها الانطلاق بشكل صحيح وهذا لا يعني أنك قد لا تضطر إلى تغيير الخطة أثناء العمل ولكنك على الأقل تكون قد وضعت حجر أساس صحيح يمكنك الاعتماد عليه سواء في تتمة العمل أو التعديل إن تطلب الأمر

إذاً اتباع هذا النهج في التخطيط يسهل عليك التصرف وفق مقتضيات الحال كإضافة أو إزالة ميزات لم تكن تخطر ببالك أساساً ، أو إصلاح خلل في مكان ما وهذا يعلمك صراحة أن تكون سلساً ومرناً في البرمجة مستعد للتعامل مع أي ظرف طارئ

3) إهمال جودة الكود

جودة الترميز هي أهم دعائم كتابة تعليمات برمجية صحيحة وتستمد الكودات صفة الجودة عندما تكون واضحة وقابلة للقراءة وإلا ستتحول إلى رموز لا معنى لها

علاوة على أن وضوح الكود هو الطريقة الأمثل لتكوين تعليمات برمجية قابلة للتنفيذ بشكل صحيح وهذه هي المهمة الأساسية للمبرمج

إن أي خلل في أبسط الأمور يمكن أن يعيق عمل الكودات البرمجية بشكل صحيح فعلى سبيل المثال عدم الاتساق مع المسافة البادئة والكتابة بالأحرف الكبيرة يعطل عمل التعليمات البرمجية كما هو موضح في المثال

كما وأن السطور الطويلة تكون عادة صعبة القراءة لذا عليك تجنب تجاوز 80 حرفاً في كل سطر من أسطر الكودات البرمجية

ولتفادي الوقوع في مثل هذه الأخطاء يمكنك الاستعانة باستخدام أدوات الفحص والتنسيق المتوفرة في جافا سكريبت فمن خلالها يمكنك إصلاح ما يمكن إصلاحه فتجنب نفسك الدخول في متاهات يصعب عليك حلها

ويبقى الخيار الأفضل للحفاظ على جودة الكودات بالنسبة لك هو معرفة الأخطاء الأكثر شيوعاً والعمل على تلافيها والتي نذكر منها

كثرة الأسطر المستخدمة في ملف أو دالة فتجزئة التعليمات البرمجية الطويلة إلى عدة أجزاء أصغر يسهل عليك اختبار كل منها على حدى

عدم الوضوح في تسمية المتغيرات القصيرة أو المحدَّدة بنوع معين

عدم وصف ترميز السلاسل والأرقام الأولية ، ولتجنب ذلك احرص على وضع القيم الدالة على هذا الترميز في ثابت واطلق عليها اسماً مناسباً

هدر الوقت في معالجة مشاكل بسيطة يمكن أن تعالج بقليل من الحنكة والمناورة في استخدام اختصارات مناسبة

إهمال البدائل المناسبة التي توصل إلى سهولة القراءة كالاستخدام المبالغ فيه في المنطق الشرطي

4) التسرع في استعمال الحل الأول:

وهذا يحدث عندما يبحث المبرمج المبتدئ عن الحلول التي تخلصه من المشاكل التي تعترضه فيسارع إلى استعمال أول حل ينتج معه دون الأخذ بعين الاعتبار ما سينتج عنه من تعقيدات ربما تعيق سير البرمجة بشكل صحيح وبالتالي توصل إلى الفشل , فليس بالضرورة أن يكون الحل الأول هو الأصح

لذا من الأفضل اكتشاف عدة حلول واختيار الأنسب منها ، ويجب هنا التنويه إلى نقطة مهمة جداً هي أن عدم التوصل إلى عدة حلول لمشكلة ما فأنت على الأغلب لم تستطع تحديد المشكلة بدقة

فدليل مهارة المبرمج يكمن في اختياره لأبسط حل في معالجة المشكلة وليس بهروبه إلى أول حل يصل إليه ليتخلص من المشكلة فوراً

5) التشبث بفكرة الحل الأول

تجنب تماماً التمسك بالحل الأول ولو تطلب منك ذلك المزيد من الجهد فعند شعورك بمجرد الشك في صحة الحل سارع فوراً إلى التخلص من الشيفرة السيئة وحاول استيعاب المشكلة وإعادة فهمها بدقة أكبر وتذكر دائماً المهارة هي الحصول على حل بسيط يسهل عليك اتخاذ القرارات المناسبة في معالجة المشكلة، كما ويمكنك الاستعانة بأدوات التحكم بالمصدر مثل GIT التي توفر العديد من الحلول المفيدة

6) الاعتماد على جوجل:

كثيراً ما يلجأ المبرمجون المبتدئون إلى حل بعض المشاكل التي تعترضهم أثناء كتابة الأكواد عن طريق محرك البحث جوجل فالمشكلة التي واجهتهم ربما واجهت الكثيرين قبلهم , فالحل إذاً موجود غالباً وهذا في الحقيقة يوفر بعض الوقت في البحث عن حل المشكلة نوعاً ما وهذا ظاهر الأمر ولكن هل فكرت أن هذا الحل الموجود على شكل سطر من التعليمات البرمجية سيستمر معك بما يتلاءم مع حالتك أنت، احرص تمام الحرص على عدم استخدام أي سطر من التعليمات البرمجية غير الواضح بالنسبة لك وإن كنت ترى فيه الحل لمشكلتك

7) عدم استخدام التغليف

والتغليف هي منظومة تعمل على حماية المتغيرات في التطبيقات عن طريق إخفاء خصائص مع الإبقاء على إمكانية الاستفادة منها وهذه المنظومة تفيد على سبيل المثال إجراء تغييرات آمنة في الأجزاء الداخلية للوظائف دون التعرض للأجزاء الأخرى وكثيراً ما يؤدي إهمال عملية التغليف إلى صعوبة صيانة الأنظمة

8) النظرة الخاطئة للمستقبل

من الضروري أن يتمتع المبرمج بنظرة ثاقبة وأن يدرس جميع الاحتمالات عن كل خطوة قادمة عند كتابة التعليمات البرمجية وهذا يفيد في اختبار الحالات المتقدمة، ولكن انتبه لا تجعل هذه النظرة هي دليلك لتنفيذ الاحتياجات المتوقعة بأن تكتب كود لا تحتاجه الآن بفرض أنك يمكن أن تحتاجه في المستقبل ابقَ قدر الإمكان محافظاً على نمط الترميز الذي تحتاجه في يومك

9) استخدام بنية بيانات خاطئة

يعتبر تحديد مواطن القوة والضعف في هياكل البيانات المستخدمة في لغة البرمجة دليل على مهارة المبرمج وخبرته في هذا المجال ويمكن توضيح هذه النقطة ببعض النماذج العملية

إذا تحدثنا عن لغة جافا سكريبت نجد أن المصفوفة هي القائمة الأكثر استخداماً وأن أكثر بنية الخريطة استخداماً هي كائن 

ولإدارة قائمة السجلات يحتوي كل سجل منها على معرف خاص بالبحث عنه يجب استخدام الخرائط (الكائنات) بدلاً من استخدام القوائم (المصفوفات)، ويعتبر استخدام القائم العددية أفضل خيار إذا كان الهدف هو دفع القيم إلى القائمة  

10) تحويل التعليمات البرمجية إلى فوضى

في حالة وجود كودات تسبب خلل وعدم انتظام في التعليمات البرمجية فيجب التعامل معها فوراً وإزالة الفوضى الناتجة كما في الحالات التالية

كود مكرر: ويحدث ذلك عند نسخ كود ولصقه في سطر برمجي مما يؤدي إلى حدوث خلل وعدم انتظام ناتجين عن تكرار الكود

إهمال استخدام ملف التكوين : في حال استخدام قيمة معينة في أماكن مختلفة في التعليمات البرمجية فإن هذه القيمة تنتمي إلى ملف التكوين الذي لابد من تكون أي قيمة جديدة مضافة إلى الشيفرة تنتمي له على أي حال 

: (if) تجنب العبارات الشرطية غير الضرورية

من المعروف أن العبارات الشرطية هي منطق يرتبط باحتمالين على الأقل ومن الضروري تجنب الشروط غير المهمة مع الحفاظ على سهولة القراءة إذاً فالمراد هنا أن توسيع الدالة بمنطق فرعي

(if) يتبع عبارة شرطية

على حساب إدراج مهمة أخرى يسبب فوضى لا داعي لها ويجب تجنبها قدر الإمكان

(if) وللتوضيح بالنسبة لموضوع العبارة الشرطية

أمعن النظر في هذا الكود

isOdd لاحظ وجود المشكلة في الدالة

ولكن هل لاحظت مشكلة أكثر وضوحاً ؟

غير ضرورية if عبارة

: هنا رمز مكافئ

11) إدراج تعليقات على الأشياء المفهومة

من الضروري وإن بدا الأمر صعباً في البداية أن تتجنب قدر الإمكان إدراج تعليقات على الأمور المفهومة والواضحة إذ يمكنك استبدالها بعناصر تحمل أسماء تضاف إلى التعليمات البرمجيةوللتوضيح شاهد المثال الذي يحوي على تعليقات إضافية

: لاحظ الفرق عند كتابة الكود بدون تعليقات في هذه الصورة

إذاً لاحظنا أن إدراج أسماء هو أمر مجدي أكثر من إدراج التعليقات غير المهمة إلا أنه لا يجب تعميم هذه القاعدة على أسس البرمجة عموماً بل هناك حالات لا يكتمل فيها الوضوح إلا بإدراج تعليقات، ففي مثل هذه الحالات ينبغي عليك هيكلة تعليقاتك لمعرفة سبب وجود هذا الكود بدلاً من سؤال وما إلى ذلك من أمور، حتى أولئك الذين يفضلون إدراج تعليقات ننصحهم بتجنب التنويه عن الأمور الواضحة ولتتبلور هذه الفكرة بشكل أعمق نلاحظ هذا المثال الذي يوضح وجود تعليقات لا داعي لوجودها

Advertisements

12) عدم إدراج الاختبارات في التعليمات البرمجية

قد يعتقد بعض المبرمجين أنهم ليسوا بحاجة إلى كتابة اختبارات في التعليمات البرمجية وعلى الأرجح يقومون باختبار برامجهم يدوياً وقد يكون ذلك من باب ثقتهم الزائدة بأنهم ليسوا بحاجة إلى كتابة اختبارات في تعليماتهم البرمجية ولكن لا يمكن اعتبار هذا الكلام سلبي بالمطلق لأنه حتى إذا كنت تريد معرفة آلية الاختبار تلقائياً فيجب عليك اختباره يدوياً

وإذا نجحت في اختبار تفاعل مع أحد تطبيقاتك وتريد إجراء نفس التفاعل تلقائياً في المرة القادمة فيجب عليك الرجوع إلى محرر التعليمات البرمجية لإضافة المزيد من التعليمات وهنا تجدر الإشارة إلى أنك قد تخونك ذاكرتك في استرجاع اختبار عمليات التحقق الناجحة بعد كل تغيير في الرمز ، لذا أسند هذه المهمة إلى الكمبيوتر وما عليك إلا أن تبدأ بالتخمين أو إنشاء عمليات التحقق الخاصة بك ولو قبل كتابة الكود

TDD فالتطوير المعتمد على اختبار

وإن كان غير متاح للجميع إلا أنه يؤثر إيجابياً على أسلوبك الذي يرشدك إلى إنشاء أفضل تصميم  

13) هل تعتقد أن المَهمة تسير على أكمل وجه؟

دعنا نشاهد هذه الصورة التي تُظهر

sumOddValues وظيفة تنفذ خاصية

هل تحتوي على خطأ ما؟

هل لاحظت أن الكود أعلاه غير مكتمل؟ على الرغم من أنه يتعامل بشكل سليم مع حالات معينة إلا أنه يحوي العديد من المشاكل سأذكر منها

المشكلة الأولى: أين معالجة الإدخال الفارغ ؟

هناك خطأ يكشف عن تنفيذ الوظيفة ناتج عن استدعائها بدون وسيطات

وهناك سببين لحدوث هذا الرمز الخاطئ

لا يجب أن تظهر تفاصيل تنفيذ وظيفتك لمستخدميها في حال لم تعمل وظيفتك مع المستخدمين وكان الخطأ ناجم عن استخدام غير صحيح فهذا سيظهر بوضوح لذا يمكنك أن تبرمج استثناءً تطرحه الوظيفة يشير إليه المستخدم كما يلي

والأفضل من ذلك أن تتفادى موضوع ظهور الخطأ بأن تبرمج وظيفتك على تجاهل المدخلات الفارغة

المشكلة الثانية: المدخلات الخاطئة لا يوجد معالجة لها

شاهد ما ستطرحه الوظيفة في حال تم جلب الدالة بقيمة كائن أو سلسلة أو عدد صحيح

هي دالّة array.reduce مع أن

إن أي شيء تستدعي به الوظيفة (42) في مثالنا السابق يسمى مصفوفة داخل دالة لأننا قمنا بتسمية مصفوفة وسيطة الوظيفة

لذا لاحظنا أن الخطأ يقول أن

42.reduce

ليس دالة

ولكن ربما لو كان الخطأ ظهر على الشكل التالي لكان أكثر جدوى

ويجب التنويه هنا إلى أن المشكلتين آنفتي الذكر هما من الأخطاء الثانوية التي يجب العمل على تلافيها بديهياً علاوة على وجود حالات تتطلب التفكير فيها والتخطيط لها كما في المثال التالي الذي يوضح ما سوف يحدث إذا استخدمنا قيم سالبة

كان يجب تسمية الدالة هنا

sumPositiveOddNumbers

لكي لا يظهر لنا الخط السابق

المشكلة الثالثة: عدم اختبار كل الحالات الصحيحة بسبب نسيان بعض الحالات الاستثنائية وما سنراه في الصورة التالية هو نموذج عن حالة سليمة وبسيطة لوظيفة لم يتم التعامل معها بشكل صحيح

تم إدراج الرقم (2) في المجموعة رغم أنه لا يجب وجوده فيها

reduce ظهرت هذه المشكلة لأن  

استخدم فقط القيمة الأولى في المجموعة كقيمة أولية للمجمع  والتي هي في مثالنا السابق رقم 2 لذا فالحل يكمن

reduce هنا في أن يقبل

وسيطة ثانية لاستخدامها كقيمة

accumulator أولية لـ

هنا تكمن ضرورة القيام باختبارات رغم أنك قد تكون قد اكتشفت المشكلة عند كتابة الكود وتضمين الاختبارات بعمليات أخرى

14) الاطمئنان المبالغ فيه لصحة التعليمات البرمجية الحالية

قد تبدو بعض الكودات مفيدة بالنسبة للمبرمجين المبتدئين فيستعملونها باطمئنان في التعليمات البرمجية الخاصة بهم، دون علمهم أنها أحياناً قد تكون سيئة ولكنها وضعت لأن المطور أجبر على وضعها بهذه الطريقة فتسبب مشاكل لدى المبتدئين ، لذا من الضروري هنا إدراج تعليق من قبل المطورين يستهدفون به المبتدئين يوضحون فيه سبب إدراج هذا الكود بهذه الطريقة

لذا يجدر بك كمبتدئ أن تضع أي كود تريد استخدامه من مكان آخر موضع الشك إلى أن تفهم ماهيته وسبب وجوده لتفادي الوقوع في أخطاء أنت بغنى عنها

15) الحرص الزائد على استخدام الطرق المثالية في البرمجة  

على الرغم من تسمية الطرق المثالية بهذا الاسم إلا أنها لا تحمل دائماً هذا المعنى وهذا يحدث عندما ينصرف جل اهتمام المبرمج المبتدئ باتباع الطرق المثالية أو على الأقل الطرق التي يراها هو بنظره مثالية متجاهلاً بعض الحالات التي تتطلب منه تصرفاً مغايراً لبعض القواعد الأساسية في البرمجة ، هناك حالات ستضعك أمام تحدي لا ينجيك منه إلا حُسن تصرفك ومهارتك التي ستحتاج إلى تنميتها من خلال تعاملك مع هذه الظروف

16) وسواس سوء الأداء  

للتخلص من وسواس الخوف من الوقوع في الأخطاء أثناء البرمجة احرص دائماً على توخي الحذر منذ البداية ، مع كل سطر برمجي انتبه جيداً واستدعي معلوماتك ومهاراتك التي تجنبك الوقوع في الخطأ ولكن هذا الحرص في تحسين أدائك قبل البدء لا يجب أن يكون مبالغاً فيه وحسن التقدير قبل البدء هو الذي سيعينك على اتخاذ القرار فيما إذا كان الوضع يستعدي تحسين الأداء قبل البدء أم أن التحسين في البعض الحالات سيكون مضيعة للوقت والجهد بدون مبرر

17) عدم اختيار تجارب تناسب المستخدمين  

من سمات المبرمج الناجح أنه دائماً ما يقوم بوضع نفسه مكان المستخدم وينظر إلى التطبيق الذي صممه أو طوره من وجهة نظر المستخدم فعلى سبيل المثال إن كانت الميزة تتضمن الحصول على معلومات يقوم المستخدم بإدخالها فقم كمطور بإلحاقها بالنموذج الذي لديك وإن كانت لإضافة رابط مع صفحة أخرى فقم بإضافتها إلى قائمة الروابط المتفرعة لديك وهذا يساعد كثيراً في الحصول على نتائج أفضل

18) تجاهل تجربة المستخدمين من قبل المطورين

لكل مبرمج طريقته وأدواته المفضلة في عملية البرمجة ومنها الجيد ومنها الأقل جودة ومنها السيء ولكن بشكل عام يمكن أن تطلق صفة الجودة على الأدوات المستخدمة في البرمجة حسب مواضعها فهناك حالات تكون الأدوات جيدة في الوقت الذي تكون فيه نفس هذه الأدوات سيئة في أماكن أخرى

فغالباً ما يفضل المبرمج المبتدئ الأدوات المتداولة بكثرة بغض النظر عن فائدتها في البرمجة الخاصة به فهو مبرمج مبتدئ ولكن لكي يبدأ هذا المبرمج بالانتقال إلى مستويات أعلى من الخبرة لابد له أن ينتقي الأدوات بناء على كفاءتها في معالجة وظائف معينة تتطلب استخدامها أصلاً فيكتسب المبرمج مزيداً من الانفتاح وحسن التصرف ويتخلص من مشكلة يعاني منها الكثيرين وهي التشبث بأدوات اعتادوا أن يتعاملوا بها مع كافة الحالات 

19) مشاكل البيانات الناتجة عن أخطاء التعليمات البرمجية 

البيانات هي الأعمدة الأساسية التي تشكل هيكلية البرامج التي هي بالأساس واجهة لدخال معلومات الجديدة أو حذف القديمة منها لذا فإن أصغر خطأ في الكود سيؤدي إلى خلل غير متوقع في البيانات وهذا ما يقع فيه بعض المبرمجين المبتدئين إذا يقومن في بعض الأحيان باستخدام كودات يظنون أنها نجحت في اختبارات التحقق باعتقادهم أن أحد الميزات المعطَّلة لا ضرورة لها وتتفاقم المشكلة عندما يقوم برنامج التحقق بإدخال مشاكل البيانات التي لم تكن مفهومة منذ البداية وبشكل مستمر مما يؤدي إلى تراكمها حتى تصل إلى مستوى لا يمكن التراجع عنه بحيث يستحيل معه استعادة الوضع السليم ولتجنب هذه المشكلة يمكنك استخدام طبقات متعددة من عمليات التحقق من صحة البيانات أو على الأقل استخدام القيود الخاصة بقاعدة البيانات والتي سنتعرف عليها الآن وذلك عند إضافة جداول وأعمدة إلى قاعدة البيانات الخاصة بك

NOT NULL قيد *

المطبق على عمود يعني استبعاد القيم الفارغة من هذا العمود من خلال تحديد مصدر الحقل على أنه ليس فارغاً في قاعدة البيانات

UNIQUE  قيد *

المطبق على العمود يعني استبعاد القيم المكررة داخل الجدول كاملاً وهذا القيد مثالي لجداول المستخدمين المتعلقة بإدخال بيانات لاسم مستخدم أو بريد إلكتروني  

CHECK قيد *

وهو تعبير مخصص وليتم قبول البيانات فيه يجب تقييمه إلى صحيح وهذا مثالي لعمود النسب المئوية الذي يحوي القيم الصحيحة من صفر إلى 100 

PRIMARY KEY قيد *

يضمن كل جدول في قاعدة البيانات مفتاح للتعريف بسجلاته وهو يعني أن قيم العمود ليست فارغة وفريدة أيضاً

FOREIGN KEY  قيد *

وهو يدل على وجوب تطابق قيم العمود مع القيم المدونة في عمود جدول آخر والذي يمثل غالباً مفتاحاً أساسياً

ومن المشاكل الشائعة التي يعاني منها المبتدئون والمتعلقة بسلامة البيانات هي التعامل الخاطئ مع المعاملات ، فإذا احتاجت مجموعة من العمليات المرتبطة مع بعضها البعض إلى تغيير مصدر البيانات نفسه فيجب أن يتم تغليفها بمعاملة تتيح التراجع عنها في حال حدوث خلل أو فشل في إحدى هذه العمليات

20) ابتكار عجلة برامج جديدة

في عالم البرمجة تتغير الأشياء بشكل مستمر ومتسارع وتتوفر الخدمات والمتطلبات بشكل يفوق قدرة فريق مواكبته كما يجب وعجلة البرامج شأنها كشأن هذه الخدمات المتغيرة لذا فقد لا تجد كمبرمج ضالتك في إحدى هذه العجلات لذا فاختراع عجلة جديد يبدو أمراً لا مفر منه ولكن في أغلب الحالات إن وجدت أن التصميم النموذجي للعجلة يلبي احتياجك فمن الأفضل أن لا تقوم بتصميم عجلة جديدة

هناك العديد من الخيارات لعجلات البرامج المتاحة عبر الإنترنت ويمكنك التجريب قبل الشراء وفق ما تحتاجه وتتميز بأنها تمكنك من رؤية تصميمها الداخلي علاوة على أنها مجانية  

21) الفكرة السلبية عن مراجعات الكود

غالباً ما يتخذ المبرمجون المبتدئون موقفاً سلبياً من مراجعات الكود ظناً منهم أنها تمثل انتقاداً لهم ولكن يجب عليك كمبرمج مبتدئ إن كنت تتبنى هذا الموقف أن تغير نظرتك تماماً وأن تستثمر مراجعات الكود بالشكل الأمثل فهي فرصتك للتعلم واكتساب مزيد من الخبرة ففي كل مرة تتعلم فيها شيئاً جديداً سيشكل بالنسبة لك قيمة عملية في هذا المجال

وعلى العكس إن نظرت إلى الموضوع نظرة أشمل فلربما تخطئ مراجعات الأكواد وتقوم أنت بالتصحيح وبالتالي فأنت أمام فرصة للتعليم والتعلم وهذا بحد ذاته مفخرة لك كمبرمج تشق طريقك نحو الاحتراف 

22) استبعاد فكرة استخدام التحكم بالمصدر

من السلبيات التي يقع بها بعض المبرمجين المبتدئين هي التقليل من قوة نظام التحكم بالمصدر، ربما يعود السبب لاعتقادهم أن التحكم بالمصدر يقتصر على تقديم تغييراتهم للآخرين والبناء عليها ولكن الموضوع يتعدى هذه الفكرة بكثير فرسائل الالتزام تقوم بتوصيل عمليات التنفيذ الخاصة بك كمبرمج مبتدئ واستخدامها لتساعد المشرفين على الكود الخاص بك في معرفة كيفية وصول الكود إلى وضعه الراهن

كما وأن من أوجه الاستفادة من التحكم في المصدر استخدام ميزات مثل خيارات التدريج والترميم الانتقائي والتخزين وإعادة الضبط والتعديل والعديد من الأدوات الأخرى القيمة لتدفق الترميز الخاص بك       

23) التقليل من استخدام البلد المشترك قدر الإمكان

يعتبر البلد المشترك مصدر مشاكل ويجب تجنبه قدر الإمكان أو على أقل تقدير تقليل استخدامه إلى أقصى حد إذ أن كلما كان النطاق عالمياً ازداد نطاق هذه الحالة المشتركة سوءاً لذا يجب المحافظة على الحالات الجديدة في نطاقات ضيقة ومن الضروري التأكد من أنها لا تتسرب إلى الأعلى   

24) عدم التعامل مع الأخطاء على أنها مفيدة 

يكره الكثيرون رؤية رسائل الخطأ الحمراء الصغيرة أثناء البرمجة لكن في الحقيقة ظهور الأخطاء يدل على أنك تزداد معرفة وتتعرف أكثر على مواطن الخلل التي تحدث حتى مع المبرمجين المحترفين فتعمل على تداركها في المستقبل فمن لا يخطئ لا يتعلم وظهور رسالة الخطأ ليس دليل الفشل 

25) الإرهاق المستمر ولفترات طويلة

يبقى عند المبرمج المبتدئ هاجس أنه يجب عليه إنجاز العمل الذي عليه مهما كلف الأمر وبأسرع وقت ممكن وهذا ما يدفعه للعمل لفترات طويلة ناسياً أنه بحاجة إلى الراحة فهذه الفترات الطويلة من الجلوس والتفكير تسبب الإرهاق ، وكثير من الأحيان يصل المبرمج بعد ساعات عمل طويلة إلى مرحلة لم يعد فيها قادراً على التفكير حتى أمام أبسط الأمور يقف عاجزاً لذا فأخذ قسط من الراحة أمر ضروري لاستعادة النشاط العقلي والتوازن الذهني 

Advertisements

Leave a comment