اشتراک‌ها
Visual Studio 2019 version 16.2.1 منتشر شد
مطالب
آموزش زبان Rust - قسمت 6 - Fuctions
توابع یکی از اجزای اساسی برنامه نویسی Rust هستند. آنها به شما این امکان را می‌دهند که یک بلوک کد را کپسوله کنید که می‌تواند بارها و بارها با ورودی‌های مختلفی فراخوانی شود. در اینجا یک مثال از یک تابع در Rust آمده‌است:
fn main() {
    println!("The sum of 2 and 3 is {}", sum(2, 3));
}

fn sum(a: i32, b: i32) -> i32 {
    a + b
}
در این مثال، تابعی را به نام sum تعریف می‌کنیم که دو آرگومان i32 را می‌گیرد و مجموع آنها را برمی گرداند. سپس تابع sum را با آرگومان‌های 2 و 3 فراخوانی می‌کنیم و نتیجه را با استفاده از println در کنسول چاپ می‌کنیم.

Function Declaration

توابع در Rust با استفاده از کلمه‌ی کلیدی fn و به دنبال آن نام تابع، پارامترها و نوع بازگشت (در صورت وجود) اعلام می‌شوند. در اینجا دستور کلی برای اعلان یک تابع در Rust آمده‌است:
fn function_name(parameter1: type1, parameter2: type2) -> return_type {
    // بدنه تابع
    // استفاده از مقادیر یارگشتی در صورت لزوم
}
در مثال بالا، تابع sum دو پارامتر، هر دو از نوع i32 را می‌گیرد و مقدار i32 را برمی گرداند.
 
Function Parameters
توابع در Rust می‌توانند صفر یا چند پارامتر را داشته باشند. پارامترها در امضای تابع، داخل پرانتز قرار گرفته و با کاما از هم جدا می‌شوند. در اینجا یک مثال، از یک تابع، با دو پارامتر آورده شده‌است:
fn greet(name: &str, age: i32) {
    println!("Hello, {}! You are {} years old.", name, age);
}
در این مثال، تابع greet دو پارامتر دارد: a &str (اشاره به یک رشته) و i32 (یک عدد صحیح). در داخل بدنه تابع، از مقادیر پارامترها برای چاپ پیام تبریک استفاده می‌کنیم.

Function Return Values
توابع در Rust می‌توانند با استفاده از کلمه‌ی کلیدی return و سپس مقدار بازگشتی، مقداری را برگردانند. یک مثال:
fn square(x: i32) -> i32 {
    return x * x;
}
در این مثال، تابع square، آرگومان i32 را می‌گیرد و square آن آرگومان را برمی‌گرداند. برای برگرداندن نتیجه، از کلمه کلیدی بازگشت استفاده می‌کنیم.
با این حال، Rust یک سینتکس مختصر را نیز برای برگرداندن مقادیر، از توابع دارد که در آن می‌توانید کلمه‌ی کلیدی return را حذف کنید و به سادگی مقداری را که باید در انتهای بدنه‌ی تابع برگردانده شود، مشخص کنید. در اینجا همان مثال، با استفاده از سینتکس کوتاه آمده‌است:
fn square(x: i32) -> i32 {
    x * x
}
در این مثال، کلمه‌ی کلیدی return را حذف کرده‌ایم و به‌سادگی مقداری را که باید به عنوان آخرین خط بدنه تابع برگردانده شود، مشخص کرده‌ایم.

Functions with Multiple Return Values
Rust همچنین از توابعی با مقادیر بازگشتی چندگانه پشتیبانی می‌کند که به آنها 'tuples' نیز می‌گویند. یک مثال:
fn swap(a: i32, b: i32) -> (i32, i32) {
    (b, a)
}
این تابع دو پارامتر i32 را می‌گیرد و یک tuple  از همان نوع را برمی‌گرداند. tuple، شامل دو مقدار ورودی مبادله شده‌است.
برای استفاده از مقادیر بازگشتی یک تابع tuple، می‌توانید tuple  را destructure کنید یا از عملگر '.' برای دسترسی به عناصر آن استفاده کنید. در این مثال هر دو روش وجود دارند: 
let (b, a) = swap(1, 2);
println!("a is {} and b is {}", a, b);

let tuple = swap(1, 2);
println!("a is {} and b is {}", tuple.1, tuple.0);
روش اول تاپل را مستقیماً به متغیرهای a و b تجزیه می‌کند؛ در حالیکه روش دوم با استفاده از عملگر نقطه، به داده‌ها دسترسی پیدا میکند.
اشتراک‌ها
آیا SPA همان قسمت Front-end است؟

It is common when working on a web application, comprised of a server-side Web API, running on a framework like ASP.NET or NestJS, and a client-side Single Page Application (SPA), running on a framework like Angular, to refer to the server-side as "the back-end" and to the client-side as "the front-end". I've been a culprit of this until recently.  

آیا SPA همان قسمت Front-end است؟
مطالب
برنامه نویسی امن به زبان C

اگر سخنان بزرگان برنامه نویسی را مطالعه کرده باشید، یکی از موارد این بود:
" هیچگاه از gets و sprintf استفاده نکنید، در غیر اینصورت شیاطین به زودی به سراغ شما خواهند آمد! (FreeBSD Secure Programming Guidelines) "
به عبارت دیگر استفاده از توابع کتابخانه‌های استاندارد زبان C ، بدون ملاحظات لازم (یا همان برنامه نویسی کلاسیک به زبان C )، منشاء بسیاری از حملات Buffer overrun است، زیرا اکثر این توابع اندازه‌ی بافر یا رشته‌ی ورودی را بررسی نمی‌کنند.
برای رفع این مشکلات که هنوز که هنوز است قربانی می‌گیرد! ، The Safe C Library پدید آمده است. این کتابخانه بر اساس استاندارد ISO TR24731 تهیه گردیده و در آن یک سری توابع مکمل، جهت بالا بردن امنیت‌ برنامه‌های تهیه شده به زبان C مطابق استاندارد ISO/IEC 9899:1999 معرفی شده است.

برای مثال مطابق استاندارد ISO/IEC JTC1 SC22 WG14 N1172 ، تابع نا امن memcpy با تابع امن زیر باید جایگزین شود:
errno_t  memcpy_s(void *dest, rsize_t dmax, const void *src, rsize_t smax)

مستندات آن‌را در فایل safe_lib_html.tar پس از دریافت کتابخانه می‌توانید مشاهده نمائید.

همچنین اخیرا به عنوان مکمل این مجموعه، یک کتابخانه‌ی ریاضی امن نیز تهیه شده است.

پ.ن.
شبیه به همین مورد در اینترفیس پلاگین‌های IDA-Pro در نگارش‌های اخیر آن اعمال شده است و برنامه نویس را وادار می‌کند که از نمونه‌های معادل امن در آن محیط استفاده کند.
//pro.h
// We forbid using dangerous functions in IDA Pro
#ifndef USE_DANGEROUS_FUNCTIONS
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x560 || __BORLANDC__ >= 0x580) // for BCB5 (YH)
#include <stdio.h>
#endif
#undef strcpy
#define strcpy dont_use_strcpy // use qstrncpy
#define stpcpy dont_use_stpcpy // use qstpncpy
#define strncpy dont_use_strncpy // use qstrncpy
#define strcat dont_use_strcat // use qstrncat
#define strncat dont_use_strncat // use qstrncat
#define gets dont_use_gets // use fgets
#define sprintf dont_use_sprintf // use qsnprintf
#define snprintf dont_use_snprintf // use qsnprintf
#define wsprintfA dont_use_wsprintf // use qsnprintf
#endif
برای مطالعه بیشتر: The Safe C Library

اشتراک‌ها
اجرا کردن کد های جاوااسکریپت در برنامه های ASP.NET Core

Not many are familiar with this awesome feature of dotnet core. Aspnet team is actively maintaining a project named  JavascriptServices ; Along with other packages, it includes the NodeServices package. Using this package, one can easily create an instance of node and execute JavaScript code (function) in the backend. If you think of it right now, you can see that it actually opens up a wide variety of development opportunities. By opportunities, I mean; the ASP.NET core project is trying hard to make its package eco-system (NuGet) rich but while doing it, why not get advantages of other package eco-system as well, right? When I talk about other than nuget package manager, the first name that comes to my mind is Npm (node package manager). Npm is the largest package manager out there on this very day and its growing rapidly. By using NodeServices package, we can now use (not all of the npm packages but) most of the npm packages in our backend development. So, let me show you how to configure NodeServices in your aspnet core project and use it to execute JavaScript code on the backend.

 
اجرا کردن کد های جاوااسکریپت در برنامه های ASP.NET Core
اشتراک‌ها
مقایسه‌ای بین Mapperly و AutoMapper
There is a better alternative — a mapping library based on source generators And the name of this library is Mapperly ( https://github.com/riok/mapperly)
This library solves the problems of AutoMapper and doesn’t exclude the use of manual mapping if you really want to :)
مقایسه‌ای بین Mapperly و AutoMapper
اشتراک‌ها
9 نکته برای نوشتن برنامه های امن asp.net mvc

Security is one of the most important aspects of any application – and when we talk about security, particularly in ASP.NET applications, it is not limited to development. A secure app involves multiple layers of security in the configuration, framework, web server, database server, and more. In this post, we’ll take a look at the top nine tips for writing secure applications in ASP.NET. 

9 نکته برای نوشتن برنامه های امن asp.net mvc
اشتراک‌ها
کتاب رایگان WPF Debugging and Performance Succinctly

WPF allows you to build modern desktop applications for Windows, and part of building an application is debugging code and optimizing performance. In Alessandro Del Sole’s WPF Debugging and Performance Succinctly, you will learn how to debug a WPF application by leveraging all the powerful tools in Visual Studio, including the most recent additions that allow you to investigate the behavior of the UI at runtime. Also, you will learn how to analyze and improve an application’s performance in order to provide your customers with the best possible experience and thereby make them happy.

Table of Contents
  1. Debugging WPF Applications
  2. Stepping Through Code
  3. Working with Debug Windows
  4. Debugger Visualizers and Trace Listeners
  5. XAML Debugging
  6. Analyzing the UI Performances
  7. Analyzing the Application Performances 
کتاب رایگان WPF Debugging and Performance Succinctly