User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
user:embedded_c_code_doesn_t_have_to_be_ugly [2020/05/11 18:55] – [7. Code comments] Igor Yefmovuser:embedded_c_code_doesn_t_have_to_be_ugly [2020/05/11 18:59] – [3. #define (and const) vs. enum] Igor Yefmov
Line 69: Line 69:
  
 As such (barring external dependencies) I always advise on using the latest stable language standard supported by the toolchain that your organization is comfortable with. And yes, that means that engineers must continually improve their grasp of the language and be on top of the latest stable standard to efficiently take advantage of the improvements provided by that standard. As such (barring external dependencies) I always advise on using the latest stable language standard supported by the toolchain that your organization is comfortable with. And yes, that means that engineers must continually improve their grasp of the language and be on top of the latest stable standard to efficiently take advantage of the improvements provided by that standard.
-==== 3. #define (and const) vs. enum ====+==== 3. #define (and const) vs. enum and magic numbers ====
 So much has been said about the many advantages of pushing as much work as possible away from the preprocessor and into the compiler that is amazes me to still see tons of ''#define'''s in the modern code where language standard features would provide numerous benefits over the plain old text-based code processing that knows nothing of the code structure or the data types used. So much has been said about the many advantages of pushing as much work as possible away from the preprocessor and into the compiler that is amazes me to still see tons of ''#define'''s in the modern code where language standard features would provide numerous benefits over the plain old text-based code processing that knows nothing of the code structure or the data types used.
  
Line 96: Line 96:
  
 <code C>enum{ s2r_uvc_stream_buf_size = s2r_ep_bulk_video_pkts_count * s2r_ep_bulk_video_pkt_size };</code> <code C>enum{ s2r_uvc_stream_buf_size = s2r_ep_bulk_video_pkts_count * s2r_ep_bulk_video_pkt_size };</code>
 +
 +=== Magic numbers ===
 +You know, that kind:
 +<code C>if(interface == 3){</code>
 +
 +Compare that to this code and tell me - which one makes you understand what that code does?
 +<code C>if(interface == s2r_id_audio_stream_ifc){</code>
  
 ==== 4. Bit manipulations vs. structured data ==== ==== 4. Bit manipulations vs. structured data ====

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information