- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
function display(id:number, name:string)
{
print("Id = " + id + ", Name = " + name);
}
function main() {
display(1, "asd");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
function display(id:number, name:string)
{
print("Id = " + id + ", Name = " + name);
}
function main() {
display(1, "asd");
}
А ваш говно компайлер умеет так делать?
>> Output:
Id = 1., Name = asd
+1
// Define the module
define(function(require) {
// Require empty list error
var EmptyListError = require('../errors/property_errors').EmptyListError;
// Character-rank list class
function WeightedList(/* ...keys */) {
this._total = 0;
this._generateList.apply(this, arguments);
}
WeightedList.prototype._generateList = function() {
var collection;
if (typeof arguments[0] == 'object') {
collection = arguments[0];
} else {
collection = arguments;
}
for (var i = 0; i < collection.length; i++) {
this[collection[i]] = this[collection[i]] === undefined ? 1 : this[collection[i]] + 1;
this._total++;
}
}
WeightedList.prototype.getRandomKey = function() {
if (this._total < 1)
throw new EmptyListError();
var num = Math.random();
var lowerBound = 0;
var keys = Object.keys(this);
for (var i = 0; i < keys.length; i++) {
if (keys[i] != "_total") {
if (num < lowerBound + this[keys[i]] / this._total) {
return keys[i];
}
lowerBound += this[keys[i]] / this._total;
}
}
return keys[keys.length - 1];
};
WeightedList.prototype.increaseRank = function(key) {
if (key !== undefined && key != "_total") {
if (this[key] !== undefined) {
this[key]++;
} else {
this[key] = 1;
}
this._total++;
}
};
WeightedList.prototype.clearRanks = function() {
var keys = Object.keys(this);
for (var i = 0; i < keys.length; i++) {
if (keys[i] != "_total") {
this._total -= this[keys[i]] - 1;
this[keys[i]] = 1;
}
}
};
return WeightedList;
});
Вот почему я за четкое разделение объектов/структур и хэшей (ассоциативных массивов).
0
function test3()
{
const a = 10.5
switch (a)
{
case 10.5:
print("cool. 10.5");
break;
}
}
function test3()
{
switch ("kokoko")
{
case "kokoko":
print("pituh");
break;
}
}
Продолжаем говнокомпилить...
А ваш С такое прокомпилирует? мой - запросто :)
0
// В одном файле
// Getting gif by url
const getGifUrl = (searchQuery, gifRating) => {
const fullUrl = `${giphyUrl}${giphyApiKey}&tag=${searchQuery}&rating=${gifRating}`;
let gifSource;
let girSourceOriginal;
fetch(fullUrl).then(response => {
return response.json();
}, networkError => {
console.log(networkError);
}).then(jsonResponse => {
if (!jsonResponse)
gifSource = '';
else {
gifSource = jsonResponse.data.images.preview_gif.url;
gifSoucreOriginal = jsonResponse.data.image_original_url;
}
renderGif(gifSource, gifSoucreOriginal);
});
};
// Где-то в другом файле
// incapsulating image
const incapsulateImage = (gifUrl, gifUrlOriginal) => {
// creating gif preview tile
const image = document.createElement('img');
image.src = gifUrl;
// create link to the original gif
const linkOriginal = document.createElement('a');
linkOriginal.href = gifUrlOriginal;
// incapsulating gif tile into link
linkOriginal.appendChild(image);
// create container-tile
const tile = document.createElement('div');
tile.className = "container-tile";
// incapsulating linked gif into tile
tile.appendChild(linkOriginal);
return tile;
}
// Rendering one gif image
const renderGif = (gifUrl, gifUrlOriginal) => {
if (gifUrl) {
const imageTile = incapsulateImage(gifUrl, gifUrlOriginal);
$gifContainer.append(imageTile);
} else if (!$gifContainer.html()) {
const notFoundHeading = document.createElement('h1');
notFoundHeading.innerHTML = NOT_FOUND_TEXT;
$gifContainer.append(notFoundHeading);
}
};
const render = () => {
// Rendering whole block of gifs
const renderContainer = (searchQuery, gifCount, gifRating) => {
for (let i = 0; i < gifCount; i++) {
getGifUrl(searchQuery, gifRating);
const heading = $gifContainer.find('h1');
if (heading && heading.text() == NOT_FOUND_TEXT) {
break;
}
}
}
// ...Сетап всяких обработчиков событий на элементы...
}
Когда толком не знал про промисы (а уж тем более про модули), городил такую дичь.
+1
function main() {
(function () {
print("Hello World!");
})();
}
а ваш С компилятор может так говнокодить? а мой компилятор может :)
0
function f1()
{
print("Hello World!");
}
function run(f: () => void)
{
f();
}
function main() {
const x = f1;
x();
run(x);
}
// LLVM IL
; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"
@frmt_11120820245497078329 = internal constant [4 x i8] c"%s\0A\00"
@s_11208736881023205110 = internal constant [14 x i8] c"Hello World!\00\00"
declare i8* @malloc(i64)
declare void @free(i8*)
declare i32 @printf(i8*, ...)
define void @f1() !dbg !3 {
%1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11120820245497078329, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @s_11208736881023205110, i64 0, i64 0)), !dbg !7
br label %2, !dbg !9
2: ; preds = %0
ret void, !dbg !9
}
define void @run(void ()* %0) !dbg !10 {
%2 = alloca void ()*, align 8, !dbg !11
store void ()* %0, void ()** %2, align 8, !dbg !11
%3 = load void ()*, void ()** %2, align 8, !dbg !11
call void %3(), !dbg !13
br label %4, !dbg !14
4: ; preds = %1
ret void, !dbg !14
}
define void @main() !dbg !15 {
%1 = alloca void ()*, align 8, !dbg !16
%2 = alloca void ()*, align 8, !dbg !19
store void ()* @f1, void ()** %2, align 8, !dbg !19
%3 = load void ()*, void ()** %2, align 8, !dbg !19
call void %3(), !dbg !20
%4 = load void ()*, void ()** %2, align 8, !dbg !19
%5 = bitcast void ()** %1 to i8*, !dbg !16
call void @llvm.lifetime.start.p0i8(i64 8, i8* %5), !dbg !16
store void ()* %4, void ()** %1, align 8, !dbg !16
%6 = load void ()*, void ()** %1, align 8, !dbg !16
call void %6(), !dbg !21
%7 = bitcast void ()** %1 to i8*, !dbg !22
call void @llvm.lifetime.end.p0i8(i64 8, i8* %7), !dbg !22
br label %8, !dbg !23
8: ; preds = %0
ret void, !dbg !23
}
; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
attributes #0 = { argmemonly nofree nosync nounwind willreturn }
продолжаем говнокодить компилятор аля TypeScript в нативный код. ну это как С компилятор только без тупо-уродо-* у имен переменных
1) компилим точно также как и до этого в постах
2) получаем результат
>> Hello World!
Hello World!
−2
const connectToServerEpic = (
action$,
) => (
action$
.pipe(
ofType(CONNECT_TO_SERVER),
switchMap(({
hostname,
port,
protocol,
protocolVersion,
reconnectionTimeout,
}) => (
action$
.pipe(
ofType(RECONNECT_TO_SERVER),
takeUntil(
action$
.pipe(
ofType(DISCONNECT_FROM_SERVER),
)
),
startWith(null),
map(() => (
webSocket({
protocol: protocolVersion,
url: (
protocol
.concat('://')
.concat(hostname)
.concat(':')
.concat(port)
),
WebSocketCtor: WebSocket,
})
)),
switchMap((
webSocketConnection$,
) => (
webSocketConnection$
.pipe(
takeUntil(
action$
.pipe(
ofType(
RECONNECT_TO_SERVER,
DISCONNECT_FROM_SERVER,
),
)
),
catchError(() => (
timer(
reconnectionTimeout,
)
.pipe(
takeUntil(
action$
.pipe(
ofType(
RECONNECT_TO_SERVER,
DISCONNECT_FROM_SERVER,
),
)
),
mapTo(reconnectToServer()),
)
)),
map(receivedWebSocketMessage),
startWith(
connectionReady(
webSocketConnection$,
)
),
)),
)),
)
)),
)
)
https://itnext.io/simplifying-websockets-in-rxjs-a177b887f3b8
0
function main()
{
const ac = [1, 2, 3];
let a = ac;
print(ac[0]);
print(ac[1]);
print(ac[2]);
print(a[0]);
print(a[1]);
print(a[2]);
const ac2 = [1.0, 2.0, 3.0];
let a2 = ac2;
print(ac2[0]);
print(ac2[1]);
print(ac2[2]);
print(a2[0]);
print(a2[1]);
print(a2[2]);
const ac3 = ["item 1", "item 2", "item 3"];
let a3 = ac3;
print(ac3[0]);
print(ac3[1]);
print(ac3[2]);
print(a3[0]);
print(a3[1]);
print(a3[2]);
}
// LLVM output
; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"
@frmt_11120820245497078329 = internal constant [4 x i8] c"%s\0A\00"
@s_13298922352840505641 = internal constant [8 x i8] c"item 3\00\00"
@s_13297965777724151296 = internal constant [8 x i8] c"item 2\00\00"
@s_13300835503073214331 = internal constant [8 x i8] c"item 1\00\00"
@a_14124738666956595718 = internal constant [3 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @s_13300835503073214331, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @s_13297965777724151296, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @s_13298922352840505641, i64 0, i64 0)]
@frmt_11108397963124010376 = internal constant [4 x i8] c"%f\0A\00"
@a_17125214420326958200 = internal constant [3 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00]
@frmt_11106471618751763154 = internal constant [4 x i8] c"%d\0A\00"
@a_2366260266165782651 = internal constant [3 x i32] [i32 1, i32 2, i32 3]
declare i8* @malloc(i64)
declare void @free(i8*)
declare i32 @printf(i8*, ...)
define void @main() !dbg !3 {
%1 = alloca i32*, align 8, !dbg !7
store i32* getelementptr inbounds ([3 x i32], [3 x i32]* @a_2366260266165782651, i64 0, i64 0), i32** %1, align 8, !dbg !7
%2 = load i32*, i32** %1, align 8, !dbg !7
%3 = alloca i32*, align 8, !dbg !9
store i32* %2, i32** %3, align 8, !dbg !9
%4 = load i32*, i32** %1, align 8, !dbg !7
%5 = getelementptr i32, i32* %4, i32 0, !dbg !10
%6 = load i32, i32* %5, align 4, !dbg !10
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %6), !dbg !11
%8 = load i32*, i32** %1, align 8, !dbg !7
%9 = getelementptr i32, i32* %8, i32 1, !dbg !12
%10 = load i32, i32* %9, align 4, !dbg !12
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %10), !dbg !13
%12 = load i32*, i32** %1, align 8, !dbg !7
%13 = getelementptr i32, i32* %12, i32 2, !dbg !14
%14 = load i32, i32* %13, align 4, !dbg !14
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %14), !dbg !15
%16 = load i32*, i32** %3, align 8, !dbg !9
%17 = getelementptr i32, i32* %16, i32 0, !dbg !16
%18 = load i32, i32* %17, align 4, !dbg !16
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %18), !dbg !17
%20 = load i32*, i32** %3, align 8, !dbg !9
%21 = getelementptr i32, i32* %20, i32 1, !dbg !18
%22 = load i32, i32* %21, align 4, !dbg !18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %22), !dbg !19
%24 = load i32*, i32** %3, align 8, !dbg !9
%25 = getelementptr i32, i32* %24, i32 2, !dbg !20
%26 = load i32, i32* %25, align 4, !dbg !20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %26), !dbg !21
%28 = alloca float*, align 8, !dbg !22
store float* getelementptr inbounds ([3 x float], [3 x float]* @a_17125214420326958200, i64 0, i64 0), float** %28, align 8, !dbg !22
%29 = load float*, float** %28, align 8, !dbg !22
%30 = alloca float*, align 8, !dbg !23
store float* %29, float** %30, align 8, !dbg !23
%31 = load float*, float** %28, align 8, !dbg !22
%32 = getelementptr float, float* %31, i32 0, !dbg !24
%33 = load float, float* %32, align 4, !dbg !24
%34 = fpext float %33 to double, !dbg !25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11108397963124010376, i64 0, i64 0), double %34), !dbg !25
%36 = load float*, float** %28, align 8, !dbg !22
%37 = getelementptr float, float* %36, i32 1, !dbg !26
%38 = load float, float* %37, align 4, !dbg !26
%39 = fpext float %38 to double, !dbg !27
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11108397963124010376, i64 0, i64 0), double %39), !dbg !27
продолжаем нашу е..блю с компилятором а ля "C" но только используя синтакс TypeScript
дальше это гвно при запуска tsc.exe --emit=llvm c:\1.ts
получаем равернутую раскладку го-в-на которе можно перевести в Obj файл
а если запустим EXE получим такую Х типа "1 2 3 1 2 3 1.0 2.0 3.0 1.0 2.0 3.0 item 1 item 2 item 3 item 1 item 2 item 3"
и никакой е..бли в указателями все сука компилятор делает сам
0
type User = {
status: 'lamer' | 'junior' | 'govnokoder';
login: string;
iq: number;
}
type ChangeListener<T, K extends keyof T> = {
name: `${K & string}_Listener`;
on(newValue: T[K])
}
const UserIqListener: ChangeListener<User, 'iq'> = {
name: "iq_Listener", //ничто другое не скомпилируется
on(event: number) { //понятно, что string тут не скомпилируется
}
}
const UserStatusListener: ChangeListener<User, 'status'> = {
name: "status_Listener",
on(newValue: User["status"]) {
switch (newValue) {
case "govnokoder": { //понятно, что неверный тип тут не скомпилируется
}
}
}
}
Почему у нас нет "TypeScript"?
0
function validateUSDate( strValue )
{
var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
if(!objRegExp.test(strValue))
return false; //doesn't match pattern, bad date
else
{
var strSeparator = strValue.substring(2,3); //find date separator
var arrayDate = strValue.split(strSeparator); //split date into month, day, year
//create a lookup for months not equal to Feb.
var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
'08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31};
var intDay = (arrayDate[1]);
//check if month value and day value agree
if(arrayLookup[arrayDate[0]] != null)
{
if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
return true; //found in lookup table, good date
}
//check for February
var intYear = parseInt(arrayDate[2]);
var intMonth = parseInt(arrayDate[0]);
if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
return true; //Feb. had valid number of days
}
return false; //any other values, bad date
}
А вот этот шедевр ещё и работает...